samandesk 1.1.1 → 1.1.2

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.
@@ -52,6 +52,7 @@ function getOpenLinkFn() {
52
52
  const readyEvent = new Event("ready");
53
53
  const openEvent = new Event("open");
54
54
  const closeEvent = new Event("close");
55
+ const guestReadyEvent = new Event("guest-ready");
55
56
  function getReadyEvent() {
56
57
  return readyEvent;
57
58
  }
@@ -61,6 +62,9 @@ function getOpenEvent() {
61
62
  function getCloseEvent() {
62
63
  return closeEvent;
63
64
  }
65
+ function setGuestReadyEvent() {
66
+ return guestReadyEvent;
67
+ }
64
68
  function handleEvents(interoperation) {
65
69
  window.addEventListener("message", (event) => {
66
70
  if (!event.data.from || event.data.from !== "SamanDesk") return;
@@ -118,20 +122,35 @@ class InterOperation {
118
122
  openLink(data) {
119
123
  getOpenLinkFn()(data.data.link);
120
124
  }
125
+ setGuestReadyEvent() {
126
+ window.dispatchEvent(setGuestReadyEvent());
127
+ }
121
128
  }
122
129
  const SITE_URL = "https://samandesk.com";
123
130
  class SamanDesk {
124
131
  /**
125
132
  * ⁧این تابع در ابتدا مقدار verifiedToken را دریافت کرده و سپس مقدار token‌ را دریافت و سپس آن را ذخیره می‌کند
126
133
  */
127
- async init(verifiedToken) {
134
+ async init(config, verifiedToken) {
128
135
  this.interoperation = new InterOperation();
129
136
  this.interoperation.init();
130
137
  const frame2 = getFrame();
131
138
  const backdrop2 = getBackdrop();
132
- setFrameSrc(`${SITE_URL}/setup-interoperation/${verifiedToken}`);
133
- frame2.width = "0";
134
- frame2.style.width = "0";
139
+ setTheme({
140
+ darkMode: config.theme.darkMode ?? "light",
141
+ color: config.theme.color ?? "default"
142
+ });
143
+ setLanguage(config.language ?? "fa");
144
+ setOpenLinkFn(config.linkHandler);
145
+ this.config = config;
146
+ if (verifiedToken) {
147
+ setFrameSrc(`${SITE_URL}/setup-interoperation/${verifiedToken}`);
148
+ frame2.width = "0";
149
+ frame2.style.width = "0";
150
+ } else {
151
+ this.setStyle();
152
+ setFrameSrc(`${SITE_URL}/guest-login/${config.workspaceID}`);
153
+ }
135
154
  document.body.appendChild(backdrop2);
136
155
  document.body.appendChild(frame2);
137
156
  }
@@ -141,7 +160,8 @@ class SamanDesk {
141
160
  * @param fullScreen - تمام صفحه باز شود یا خیر
142
161
  *
143
162
  */
144
- setStyle(fullScreen, style) {
163
+ setStyle() {
164
+ var _a, _b, _c, _d;
145
165
  const frame2 = getFrame();
146
166
  const backdrop2 = getBackdrop();
147
167
  frame2.style.position = "fixed";
@@ -156,14 +176,14 @@ class SamanDesk {
156
176
  zIndex: "1000"
157
177
  };
158
178
  Object.assign(backdrop2.style, backdropStyles);
159
- if (fullScreen) {
160
- const marginTopVal = (style == null ? void 0 : style.marginTop) ?? 0;
161
- const marginBottomVal = (style == null ? void 0 : style.marginBottom) ?? 0;
179
+ if (this.config.fullScreen) {
180
+ const marginTopVal = ((_a = this.config.style) == null ? void 0 : _a.marginTop) ?? 0;
181
+ const marginBottomVal = ((_b = this.config.style) == null ? void 0 : _b.marginBottom) ?? 0;
162
182
  const totalMargin = marginTopVal + marginBottomVal;
163
183
  Object.assign(frame2.style, {
164
- bottom: (style == null ? void 0 : style.marginBottom) ? `${style.marginBottom.toString()}px` : "0",
184
+ bottom: ((_c = this.config.style) == null ? void 0 : _c.marginBottom) ? `${this.config.style.marginBottom.toString()}px` : "0",
165
185
  left: "0",
166
- top: (style == null ? void 0 : style.marginTop) ? `${style.marginTop.toString()}px` : "0",
186
+ top: ((_d = this.config.style) == null ? void 0 : _d.marginTop) ? `${this.config.style.marginTop.toString()}px` : "0",
167
187
  right: "0",
168
188
  width: "100%",
169
189
  height: `calc(100% - ${totalMargin}px)`
@@ -181,27 +201,19 @@ class SamanDesk {
181
201
  maxHeight: "660px"
182
202
  });
183
203
  }
184
- }
185
- /**
186
- * این تابع آیفریم را باز می‌کند.
187
- */
188
- open(config) {
189
- const frame2 = getFrame();
190
- const backdrop2 = getBackdrop();
191
- setTheme({
192
- darkMode: config.theme.darkMode ?? "light",
193
- color: config.theme.color ?? "default"
194
- });
195
- setLanguage(config.language ?? "fa");
196
- const src = config.link || `${SITE_URL}/department-selection?token=${getToken()}`;
197
- setFrameSrc(src);
198
- setOpenLinkFn(config.linkHandler);
199
- this.setStyle(config.fullScreen, config.style);
200
204
  document.body.appendChild(backdrop2);
201
205
  document.body.appendChild(frame2);
202
206
  backdrop2.onclick = () => {
203
207
  this.close();
204
208
  };
209
+ }
210
+ /**
211
+ * این تابع آیفریم را باز می‌کند.
212
+ */
213
+ open(link) {
214
+ const src = link || `${SITE_URL}/department-selection?token=${getToken()}`;
215
+ this.setStyle();
216
+ setFrameSrc(src);
205
217
  window.dispatchEvent(getOpenEvent());
206
218
  }
207
219
  /**
@@ -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,a,s=e=>window.open(e,"_blank","noopener");const d=document.createElement("div"),r={count:0,promises:{}};function l(){o.src=""}function c(e){o.src=e}function m(){return o}function p(){return d}const u=new Event("ready"),f=new Event("open"),g=new Event("close");function h(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(s){console.error("error while run event action")}const n=t.data,i=n.id,a=r;i in a.promises?(a.promises[i](n),delete a.promises[i]):o||console.error("Message from outside of frame is invalid")}))}class y{async init(){h(this)}setToken(e){var o;o=e.data.token,t=o,l(),window.dispatchEvent(u)}close(){l();const e=p();document.body.removeChild(e),e.onclick=null,document.body.removeChild(m()),window.dispatchEvent(g)}getConfig(e){const t={theme:n,color:i},o={language:a};!function(e,t,o){var n;const i={from:"SamanDesk",action:o,data:t,id:e};null==(n=m().contentWindow)||n.postMessage(i,"*")}(e.id,{color:t.color,theme:t.theme,language:o.language},e.action)}openLink(e){s(e.data.link)}}const b="https://samandesk.com";e.SamanDesk=class{async init(e){this.interoperation=new y,this.interoperation.init();const t=m(),o=p();c(`${b}/setup-interoperation/${e}`),t.width="0",t.style.width="0",document.body.appendChild(o),document.body.appendChild(t)}setStyle(e,t){const o=m(),n=p();o.style.position="fixed",o.style.zIndex="1000";if(Object.assign(n.style,{position:"fixed",top:"0",bottom:"0",left:"0",right:"0",backgroundColor:"rgba(0,0,0,0.5)",zIndex:"1000"}),e){const e=((null==t?void 0:t.marginTop)??0)+((null==t?void 0:t.marginBottom)??0);Object.assign(o.style,{bottom:(null==t?void 0:t.marginBottom)?`${t.marginBottom.toString()}px`:"0",left:"0",top:(null==t?void 0:t.marginTop)?`${t.marginTop.toString()}px`:"0",right:"0",width:"100%",height:`calc(100% - ${e}px)`})}else Object.assign(o.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"})}open(e){const o=m(),d=p();var r,l;r={darkMode:e.theme.darkMode??"light",color:e.theme.color??"default"},n=r.darkMode,i=r.color,l=e.language??"fa",a=l;var u;c(e.link||`${b}/department-selection?token=${t}`),(u=e.linkHandler)&&(s=u),this.setStyle(e.fullScreen,e.style),document.body.appendChild(d),document.body.appendChild(o),d.onclick=()=>{this.close()},window.dispatchEvent(f)}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](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"})}));
@@ -5,6 +5,14 @@ export type ProjectTheme = {
5
5
  /** رنگ برنامه */
6
6
  color: Color;
7
7
  };
8
+ export type GuestData = {
9
+ mobile: string;
10
+ name?: string;
11
+ family: string;
12
+ countryCode: string;
13
+ verifyToken: string;
14
+ workspaceID: string;
15
+ };
8
16
  type PromiseMap = {
9
17
  [key: number]: (data: any) => void;
10
18
  };
@@ -27,6 +35,9 @@ export declare function clearFrame(): void;
27
35
  export declare function setFrameSrc(src: string): void;
28
36
  /** ⁧تگ iframe را بر می‌گرداند ⁩ */
29
37
  export declare function getFrame(): HTMLIFrameElement;
38
+ export declare function setGuestData(data: GuestData): void;
39
+ export declare function getGuestData(): GuestData | undefined;
40
+ export declare function clearGuestData(): void;
30
41
  /** تم و رنگ کتابخانه را بر می‌گرداند */
31
42
  export declare function getTheme(): {
32
43
  theme: "light" | "dark" | undefined;
@@ -11,6 +11,10 @@ export declare function getOpenEvent(): Event;
11
11
  * ایونت بسته‌شدن کتابخانه را بر می‌گرداند
12
12
  */
13
13
  export declare function getCloseEvent(): Event;
14
+ /**
15
+ * ایونت آماده‌شدن حالت مهمان را بر می‌گرداند
16
+ */
17
+ export declare function setGuestReadyEvent(): Event;
14
18
  /**
15
19
  * ⁧eventهایی که از بیرون به داخل می‌ایند را اعتبار سنجی و سپس کار خواسته شده را انجام می‌دهد
16
20
  */
@@ -1,11 +1,5 @@
1
1
  import { ProjectTheme } from './data';
2
2
  export interface OpenConfig {
3
- /**
4
- * اگر لینک مستقیما از بیرون آمده باشد همان را باز می‌کند
5
- * این اتفاق در شرایطی رخ می‌دهد که میزبان می‌خواهد از لینکی که در اختیارش قرار گرفته است مستقیما استفاده کند
6
- * اگر لینک را در ورودی ارسال نکند، خودکار به صفحه‌ی انتخاب دپارتمان می‌رویم و ادامه‌ی کار توسط سامان دسک صورت می‌گیرد
7
- */
8
- link?: string;
9
3
  /**
10
4
  * کتابخانه به صورت تمام صفحه باز شود یا خیر
11
5
  *
@@ -22,6 +16,8 @@ export interface OpenConfig {
22
16
  language: string;
23
17
  /** تابع مدیریت‌کننده‌ی لینک‌ها */
24
18
  linkHandler?: (link: string) => void;
19
+ /** شناسه محیط کاری پروژه */
20
+ workspaceID?: string;
25
21
  style?: {
26
22
  /** فاصله از بالا در حالت تمام صفحه */
27
23
  marginTop?: number;
@@ -34,10 +30,11 @@ export declare class SamanDesk {
34
30
  * ⁧ شی‌ء کلاس InterOperation
35
31
  */
36
32
  private interoperation?;
33
+ private config;
37
34
  /**
38
35
  * ⁧این تابع در ابتدا مقدار verifiedToken را دریافت کرده و سپس مقدار token‌ را دریافت و سپس آن را ذخیره می‌کند
39
36
  */
40
- init(verifiedToken: string): Promise<void>;
37
+ init(config: OpenConfig, verifiedToken?: string): Promise<void>;
41
38
  /**
42
39
  * استایل مربوط به آیفریم را تنظیم می‌کند
43
40
  *
@@ -48,7 +45,7 @@ export declare class SamanDesk {
48
45
  /**
49
46
  * این تابع آیفریم را باز می‌کند.
50
47
  */
51
- open(config: OpenConfig): void;
48
+ open(link?: string): void;
52
49
  /**
53
50
  * بستن کتابخانه
54
51
  */
@@ -29,5 +29,6 @@ export declare class InterOperation {
29
29
  openLink(data: MessageData<{
30
30
  link: string;
31
31
  }>): void;
32
+ setGuestReadyEvent(): void;
32
33
  }
33
34
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "samandesk",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "files": [