samandesk 1.0.12 → 1.0.14

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/data.d.ts CHANGED
@@ -20,4 +20,8 @@ export declare function clearFrame(): void;
20
20
  export declare function setFrameSrc(src: string): void;
21
21
  /** ⁧تگ iframe را بر می‌گرداند ⁩ */
22
22
  export declare function getFrame(): HTMLIFrameElement;
23
+ /** تم کتابخانه را بر می‌گرداند */
24
+ export declare function getTheme(): "light" | "dark" | undefined;
25
+ /** ‌ تم جدید کتابخانه را تنظیم می‌کند */
26
+ export declare function setTheme(newTheme: 'light' | 'dark'): void;
23
27
  export {};
package/dist/index.d.ts CHANGED
@@ -12,6 +12,14 @@ export interface OpenConfig {
12
12
  * ⁧در این حالت یک overlay پشت کتابخانه قرار خواهد گرفت
13
13
  */
14
14
  fullScreen: boolean;
15
+ /**
16
+ * تم کتابخانه به چه صورت باشد؟
17
+ *
18
+ * ⁧'light': تم کتابخانه روشن است
19
+ *
20
+ * ⁧'dark': تم برنامه تاریک است
21
+ */
22
+ theme?: 'light' | 'dark';
15
23
  }
16
24
  export declare class SamanDesk {
17
25
  /**
@@ -2,7 +2,7 @@ import { FunctionKeys } from 'utility-types';
2
2
  /**
3
3
  * این تابع برای فراخوانی متدهاییست که مقداری بر نمی‌گردانند
4
4
  */
5
- export declare function post(action: keyof InterOperation, data?: object): void;
5
+ export declare function post(action: string, data?: object): void;
6
6
  /**
7
7
  * این تابع برای فراخوانی متدهاییست که مقدار بر می‌گردانند
8
8
  */
@@ -13,4 +13,6 @@ export declare class InterOperation {
13
13
  setToken(data: any): void;
14
14
  /** بستن کتابخانه */
15
15
  close(): void;
16
+ /** تم کتابخانه را به بیرون اطلاع می‌دهد */
17
+ getTheme(data: any): void;
16
18
  }
@@ -1,72 +1,90 @@
1
- let l;
2
- const a = document.createElement("iframe"), m = {
1
+ let m;
2
+ const a = document.createElement("iframe");
3
+ let p;
4
+ const u = {
3
5
  count: 0,
4
6
  promises: {}
5
7
  };
6
- function p() {
7
- return m;
8
+ function f() {
9
+ return u;
8
10
  }
9
- function u(o) {
10
- l = o;
11
+ function h(n) {
12
+ m = n;
11
13
  }
12
- function f() {
13
- return l;
14
+ function g() {
15
+ return m;
14
16
  }
15
17
  function c() {
16
18
  a.src = "";
17
19
  }
18
- function d(o) {
19
- a.src = o;
20
+ function d(n) {
21
+ a.src = n;
20
22
  }
21
- function s() {
23
+ function r() {
22
24
  return a;
23
25
  }
24
- const h = new Event("ready"), w = new Event("open"), g = new Event("close");
25
- function y() {
26
- return h;
26
+ function w() {
27
+ return p;
27
28
  }
28
- function E() {
29
- return w;
29
+ function y(n) {
30
+ p = n;
30
31
  }
31
- function x() {
32
- return g;
32
+ const E = new Event("ready"), x = new Event("open"), v = new Event("close");
33
+ function k() {
34
+ return E;
33
35
  }
34
- function k(o) {
36
+ function b() {
37
+ return x;
38
+ }
39
+ function S() {
40
+ return v;
41
+ }
42
+ function T(n) {
35
43
  window.addEventListener("message", (e) => {
36
44
  if (!e.data.from || e.data.from !== "SamanDesk")
37
45
  return;
38
46
  let t = !1;
39
47
  console.log(`message from (${e.origin})`, e);
40
48
  try {
41
- o[e.data.action](e.data.data), t = !0;
49
+ n[e.data.action](e.data), t = !0;
42
50
  } catch {
43
51
  console.error("error while run event action");
44
52
  }
45
- const n = e.data, r = n.id, i = p();
46
- r in i.promises ? (i.promises[r](n), delete i.promises[r]) : t || console.error("Message from outside of frame is invalid");
53
+ const o = e.data, i = o.id, s = f();
54
+ i in s.promises ? (s.promises[i](o), delete s.promises[i]) : t || console.error("Message from outside of frame is invalid");
47
55
  });
48
56
  }
49
- class v {
57
+ function O(n, e, t) {
58
+ var s;
59
+ const o = { from: "SamanDesk", action: t, data: e, id: n };
60
+ (s = r().contentWindow) == null || s.postMessage(o, "*");
61
+ }
62
+ class R {
50
63
  async init() {
51
- k(this);
64
+ T(this);
52
65
  }
53
66
  /** توکن را از میزبان دریافت کرده و آن را ذخیره می‌کند. سپس به میزبان اعلام می‌کند که آماده‌ی ادامه‌ی کار است */
54
67
  setToken(e) {
55
- u(e.token), c(), window.dispatchEvent(y());
68
+ h(e.data.token), c(), window.dispatchEvent(k());
56
69
  }
57
70
  /** بستن کتابخانه */
58
71
  close() {
59
- c(), document.body.removeChild(s()), window.dispatchEvent(x());
72
+ c(), document.body.removeChild(r()), window.dispatchEvent(S());
73
+ }
74
+ /** تم کتابخانه را به بیرون اطلاع می‌دهد */
75
+ getTheme(e) {
76
+ O(e.id, { theme: w() }, e.action);
60
77
  }
61
78
  }
62
- class S {
79
+ const l = "http://localhost:2525";
80
+ class C {
63
81
  /**
64
82
  * ⁧این تابع در ابتدا مقدار verifiedToken را دریافت کرده و سپس مقدار token‌ را دریافت و سپس آن را ذخیره می‌کند
65
83
  */
66
84
  async init(e) {
67
- new v().init();
68
- const n = s();
69
- d(`https://samandesk.com/setup-interoperation/${e}`), n.width = "0", n.style.width = "0", document.body.appendChild(n);
85
+ new R().init();
86
+ const o = r();
87
+ d(`${l}/setup-interoperation/${e}`), o.width = "0", o.style.width = "0", document.body.appendChild(o);
70
88
  }
71
89
  /**
72
90
  * استایل مربوط به آیفریم را تنظیم می‌کند
@@ -75,7 +93,7 @@ class S {
75
93
  *
76
94
  */
77
95
  setStyle(e) {
78
- const t = s();
96
+ const t = r();
79
97
  t.style.position = "fixed", t.style.zIndex = "1000", e ? (Object.assign(t.style, {
80
98
  bottom: "0",
81
99
  left: "0",
@@ -97,10 +115,12 @@ class S {
97
115
  * این تابع آیفریم را باز می‌کند.
98
116
  */
99
117
  open(e) {
100
- const t = s(), n = e.link || `https://samandesk.com/department-selection?token=${f()}`;
101
- d(n), this.setStyle(e.fullScreen), document.body.appendChild(t), window.dispatchEvent(E());
118
+ const t = r();
119
+ y(e.theme ?? "light");
120
+ const o = e.link || `${l}/department-selection?token=${g()}`;
121
+ d(o), this.setStyle(e.fullScreen), document.body.appendChild(t), window.dispatchEvent(b());
102
122
  }
103
123
  }
104
124
  export {
105
- S as SamanDesk
125
+ C as SamanDesk
106
126
  };
@@ -1 +1 @@
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(o){i=o}function h(){return i}function l(){a.src=""}function f(o){a.src=o}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(o){window.addEventListener("message",e=>{if(!e.data.from||e.data.from!=="SamanDesk")return;let t=!1;console.log(`message from (${e.origin})`,e);try{o[e.data.action](e.data.data),t=!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]):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 n=r();f(`https://samandesk.com/setup-interoperation/${e}`),n.width="0",n.style.width="0",document.body.appendChild(n)}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(),n=e.link||`https://samandesk.com/department-selection?token=${h()}`;f(n),this.setStyle(e.fullScreen),document.body.appendChild(t),window.dispatchEvent(x())}}s.SamanDesk=S,Object.defineProperty(s,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 d=document.createElement("iframe");let l;const p={count:0,promises:{}};function h(){return p}function g(n){i=n}function y(){return i}function f(){d.src=""}function m(n){d.src=n}function a(){return d}function w(){return l}function E(n){l=n}const x=new Event("ready"),v=new Event("open"),S=new Event("close");function b(){return x}function k(){return v}function T(){return S}function D(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),t=!0}catch{console.error("error while run event action")}const o=e.data,c=o.id,r=h();c in r.promises?(r.promises[c](o),delete r.promises[c]):t||console.error("Message from outside of frame is invalid")})}function O(n,e,t){var r;const o={from:"SamanDesk",action:t,data:e,id:n};(r=a().contentWindow)==null||r.postMessage(o,"*")}class R{async init(){D(this)}setToken(e){g(e.data.token),f(),window.dispatchEvent(b())}close(){f(),document.body.removeChild(a()),window.dispatchEvent(T())}getTheme(e){O(e.id,{theme:w()},e.action)}}const u="http://localhost:2525";class ${async init(e){new R().init();const o=a();m(`${u}/setup-interoperation/${e}`),o.width="0",o.style.width="0",document.body.appendChild(o)}setStyle(e){const t=a();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=a();E(e.theme??"light");const o=e.link||`${u}/department-selection?token=${y()}`;m(o),this.setStyle(e.fullScreen),document.body.appendChild(t),window.dispatchEvent(k())}}s.SamanDesk=$,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.12",
3
+ "version": "1.0.14",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "files": [
@@ -16,7 +16,11 @@
16
16
  "types": "./dist/index.d.ts"
17
17
  }
18
18
  },
19
+ "scripts": {
20
+ "start": "yarn link && cross-env VITE_DEV_MODE=1 yarn vite build --watch"
21
+ },
19
22
  "devDependencies": {
23
+ "cross-env": "^7.0.3",
20
24
  "typescript": "^5.2.2",
21
25
  "utility-types": "^3.10.0",
22
26
  "vite": "^4.4.9",