samandesk 1.0.20 → 1.0.22

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.
@@ -1,12 +1,12 @@
1
1
  let p;
2
2
  const c = document.createElement("iframe");
3
- let u;
4
- const h = document.createElement("div"), f = {
3
+ let u, h;
4
+ const f = document.createElement("div"), g = {
5
5
  count: 0,
6
6
  promises: {}
7
7
  };
8
- function g() {
9
- return f;
8
+ function k() {
9
+ return g;
10
10
  }
11
11
  function b(n) {
12
12
  p = n;
@@ -23,26 +23,26 @@ function l(n) {
23
23
  function i() {
24
24
  return c;
25
25
  }
26
- function k() {
27
- return u;
26
+ function E() {
27
+ return { theme: u, color: h };
28
28
  }
29
29
  function w(n) {
30
- u = n;
30
+ u = n.darkMode, h = n.color;
31
31
  }
32
32
  function a() {
33
- return h;
34
- }
35
- const E = new Event("ready"), x = new Event("open"), v = new Event("close");
36
- function S() {
37
- return E;
33
+ return f;
38
34
  }
35
+ const x = new Event("ready"), v = new Event("open"), S = new Event("close");
39
36
  function C() {
40
37
  return x;
41
38
  }
42
- function T() {
39
+ function D() {
43
40
  return v;
44
41
  }
45
- function O(n) {
42
+ function O() {
43
+ return S;
44
+ }
45
+ function T(n) {
46
46
  window.addEventListener("message", (e) => {
47
47
  if (!e.data.from || e.data.from !== "SamanDesk")
48
48
  return;
@@ -53,32 +53,33 @@ function O(n) {
53
53
  } catch {
54
54
  console.error("error while run event action");
55
55
  }
56
- const o = e.data, s = o.id, r = g();
56
+ const o = e.data, s = o.id, r = k();
57
57
  s in r.promises ? (r.promises[s](o), delete r.promises[s]) : t || console.error("Message from outside of frame is invalid");
58
58
  });
59
59
  }
60
- function D(n, e, t) {
60
+ function I(n, e, t) {
61
61
  var r;
62
62
  const o = { from: "SamanDesk", action: t, data: e, id: n };
63
63
  (r = i().contentWindow) == null || r.postMessage(o, "*");
64
64
  }
65
- class I {
65
+ class M {
66
66
  async init() {
67
- O(this);
67
+ T(this);
68
68
  }
69
69
  /** توکن را از میزبان دریافت کرده و آن را ذخیره می‌کند. سپس به میزبان اعلام می‌کند که آماده‌ی ادامه‌ی کار است */
70
70
  setToken(e) {
71
- b(e.data.token), d(), window.dispatchEvent(S());
71
+ b(e.data.token), d(), window.dispatchEvent(C());
72
72
  }
73
73
  /** بستن کتابخانه */
74
74
  close() {
75
75
  d();
76
76
  const e = a();
77
- document.body.removeChild(e), e.onclick = null, document.body.removeChild(i()), window.dispatchEvent(T());
77
+ document.body.removeChild(e), e.onclick = null, document.body.removeChild(i()), window.dispatchEvent(O());
78
78
  }
79
79
  /** تم کتابخانه را به بیرون اطلاع می‌دهد */
80
80
  getTheme(e) {
81
- D(e.id, { theme: k() }, e.action);
81
+ const t = E();
82
+ I(e.id, t, e.action);
82
83
  }
83
84
  }
84
85
  const m = {}.VITE_DEV_MODE === "1" ? "http://localhost:2525" : "https://samandesk.com";
@@ -87,7 +88,7 @@ class $ {
87
88
  * ⁧این تابع در ابتدا مقدار verifiedToken را دریافت کرده و سپس مقدار token‌ را دریافت و سپس آن را ذخیره می‌کند
88
89
  */
89
90
  async init(e) {
90
- this.interoperation = new I(), this.interoperation.init();
91
+ this.interoperation = new M(), this.interoperation.init();
91
92
  const t = i(), o = a();
92
93
  l(`${m}/setup-interoperation/${e}`), t.width = "0", t.style.width = "0", document.body.appendChild(o), document.body.appendChild(t);
93
94
  }
@@ -132,11 +133,14 @@ class $ {
132
133
  */
133
134
  open(e) {
134
135
  const t = i(), o = a();
135
- w(e.theme ?? "light");
136
+ w({
137
+ darkMode: e.theme.darkMode ?? "light",
138
+ color: e.theme.color ?? "default"
139
+ });
136
140
  const s = e.link || `${m}/department-selection?token=${y()}`;
137
141
  l(s), this.setStyle(e.fullScreen), document.body.appendChild(o), document.body.appendChild(t), o.onclick = () => {
138
142
  this.close();
139
- }, window.dispatchEvent(C());
143
+ }, window.dispatchEvent(D());
140
144
  }
141
145
  /**
142
146
  * بستن کتابخانه
@@ -1 +1 @@
1
- (function(i,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(i=typeof globalThis<"u"?globalThis:i||self,r(i.SamanDesk={}))})(this,function(i){"use strict";let r;const l=document.createElement("iframe");let p;const h=document.createElement("div"),g={count:0,promises:{}};function y(){return g}function b(n){r=n}function k(){return r}function m(){l.src=""}function u(n){l.src=n}function c(){return l}function w(){return p}function E(n){p=n}function d(){return h}const x=new Event("ready"),v=new Event("open"),S=new Event("close");function T(){return x}function C(){return v}function D(){return S}function O(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,s=o.id,a=y();s in a.promises?(a.promises[s](o),delete a.promises[s]):t||console.error("Message from outside of frame is invalid")})}function I(n,e,t){var a;const o={from:"SamanDesk",action:t,data:e,id:n};(a=c().contentWindow)==null||a.postMessage(o,"*")}class j{async init(){O(this)}setToken(e){b(e.data.token),m(),window.dispatchEvent(T())}close(){m();const e=d();document.body.removeChild(e),e.onclick=null,document.body.removeChild(c()),window.dispatchEvent(D())}getTheme(e){I(e.id,{theme:w()},e.action)}}const f={}.VITE_DEV_MODE==="1"?"http://localhost:2525":"https://samandesk.com";class R{async init(e){this.interoperation=new j,this.interoperation.init();const t=c(),o=d();u(`${f}/setup-interoperation/${e}`),t.width="0",t.style.width="0",document.body.appendChild(o),document.body.appendChild(t)}setStyle(e){const t=c(),o=d();t.style.position="fixed",t.style.zIndex="1000";const s={position:"fixed",top:"0",bottom:"0",left:"0",right:"0",backgroundColor:"rgba(0,0,0,0.5)",zIndex:"1000"};Object.assign(o.style,s),e?(Object.assign(t.style,{bottom:"0",left:"0",top:"0",right:"0",width:"100%"}),t.width="100%",t.height="100%"):Object.assign(t.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 t=c(),o=d();E(e.theme??"light");const s=e.link||`${f}/department-selection?token=${k()}`;u(s),this.setStyle(e.fullScreen),document.body.appendChild(o),document.body.appendChild(t),o.onclick=()=>{this.close()},window.dispatchEvent(C())}close(){var e;(e=this.interoperation)==null||e.close()}}i.SamanDesk=R,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
1
+ (function(i,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(i=typeof globalThis<"u"?globalThis:i||self,r(i.SamanDesk={}))})(this,function(i){"use strict";let r;const l=document.createElement("iframe");let p,m;const g=document.createElement("div"),k={count:0,promises:{}};function y(){return k}function b(n){r=n}function E(){return r}function u(){l.src=""}function f(n){l.src=n}function c(){return l}function w(){return{theme:p,color:m}}function x(n){p=n.darkMode,m=n.color}function d(){return g}const v=new Event("ready"),S=new Event("open"),T=new Event("close");function D(){return v}function C(){return S}function O(){return T}function M(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,s=o.id,a=y();s in a.promises?(a.promises[s](o),delete a.promises[s]):t||console.error("Message from outside of frame is invalid")})}function I(n,e,t){var a;const o={from:"SamanDesk",action:t,data:e,id:n};(a=c().contentWindow)==null||a.postMessage(o,"*")}class j{async init(){M(this)}setToken(e){b(e.data.token),u(),window.dispatchEvent(D())}close(){u();const e=d();document.body.removeChild(e),e.onclick=null,document.body.removeChild(c()),window.dispatchEvent(O())}getTheme(e){const t=w();I(e.id,t,e.action)}}const h={}.VITE_DEV_MODE==="1"?"http://localhost:2525":"https://samandesk.com";class R{async init(e){this.interoperation=new j,this.interoperation.init();const t=c(),o=d();f(`${h}/setup-interoperation/${e}`),t.width="0",t.style.width="0",document.body.appendChild(o),document.body.appendChild(t)}setStyle(e){const t=c(),o=d();t.style.position="fixed",t.style.zIndex="1000";const s={position:"fixed",top:"0",bottom:"0",left:"0",right:"0",backgroundColor:"rgba(0,0,0,0.5)",zIndex:"1000"};Object.assign(o.style,s),e?(Object.assign(t.style,{bottom:"0",left:"0",top:"0",right:"0",width:"100%"}),t.width="100%",t.height="100%"):Object.assign(t.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 t=c(),o=d();x({darkMode:e.theme.darkMode??"light",color:e.theme.color??"default"});const s=e.link||`${h}/department-selection?token=${E()}`;f(s),this.setStyle(e.fullScreen),document.body.appendChild(o),document.body.appendChild(t),o.onclick=()=>{this.close()},window.dispatchEvent(C())}close(){var e;(e=this.interoperation)==null||e.close()}}i.SamanDesk=R,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
@@ -1,3 +1,10 @@
1
+ import { Color } from '../library-colors';
2
+ export type ProjectTheme = {
3
+ /** روشن یا تیره‌بودن تم برنامه */
4
+ darkMode: 'light' | 'dark';
5
+ /** رنگ برنامه */
6
+ color: Color;
7
+ };
1
8
  type PromiseMap = {
2
9
  [key: number]: (data: any) => void;
3
10
  };
@@ -20,10 +27,13 @@ export declare function clearFrame(): void;
20
27
  export declare function setFrameSrc(src: string): void;
21
28
  /** ⁧تگ iframe را بر می‌گرداند ⁩ */
22
29
  export declare function getFrame(): HTMLIFrameElement;
23
- /** تم کتابخانه را بر می‌گرداند */
24
- export declare function getTheme(): "light" | "dark" | undefined;
25
- /** تم جدید کتابخانه را تنظیم می‌کند */
26
- export declare function setTheme(newTheme: 'light' | 'dark'): void;
30
+ /** تم و رنگ کتابخانه را بر می‌گرداند */
31
+ export declare function getTheme(): {
32
+ theme: "light" | "dark" | undefined;
33
+ color: Color;
34
+ };
35
+ /** ‌ تم و رنگ جدید کتابخانه را تنظیم می‌کند */
36
+ export declare function setTheme(newTheme: ProjectTheme): void;
27
37
  /** عنصر بکدراپ را برمی‌گرداند */
28
38
  export declare function getBackdrop(): HTMLDivElement;
29
39
  export {};
@@ -1,3 +1,4 @@
1
+ import { ProjectTheme } from './data';
1
2
  export interface OpenConfig {
2
3
  /**
3
4
  * اگر لینک مستقیما از بیرون آمده باشد همان را باز می‌کند
@@ -12,14 +13,11 @@ export interface OpenConfig {
12
13
  * ⁧در این حالت یک overlay پشت کتابخانه قرار خواهد گرفت
13
14
  */
14
15
  fullScreen: boolean;
15
- /**
16
- * تم کتابخانه به چه صورت باشد؟
17
- *
18
- * ⁧'light': تم کتابخانه روشن است
19
- *
20
- * ⁧'dark': تم برنامه تاریک است
16
+ /** تم کتابخانه شامل :
17
+ * روشن یا تیره بودن کتابخانه
18
+ * رنگ تم کتابخانه
21
19
  */
22
- theme?: 'light' | 'dark';
20
+ theme: Partial<ProjectTheme>;
23
21
  }
24
22
  export declare class SamanDesk {
25
23
  /**
@@ -1,4 +1,4 @@
1
- import { FunctionKeys } from 'utility-types';
1
+ import type { FunctionKeys } from 'utility-types';
2
2
  /**
3
3
  * این تابع برای فراخوانی متدهاییست که مقداری بر نمی‌گردانند
4
4
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "samandesk",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "files": [
@@ -8,16 +8,17 @@
8
8
  ],
9
9
  "main": "./dist/saman-desk.umd.cjs",
10
10
  "module": "./dist/saman-desk.js",
11
- "types": "./dist/index.d.ts",
11
+ "types": "./dist/src/index.d.ts",
12
12
  "exports": {
13
13
  ".": {
14
14
  "import": "./dist/saman-desk.js",
15
15
  "require": "./dist/saman-desk.umd.cjs",
16
- "types": "./dist/index.d.ts"
16
+ "types": "./dist/src/index.d.ts"
17
17
  }
18
18
  },
19
19
  "scripts": {
20
- "start": "yarn link && cross-env VITE_DEV_MODE=1 yarn vite build --watch"
20
+ "start": "yarn link && cross-env VITE_DEV_MODE=1 yarn vite build --watch",
21
+ "prepublish": "vite build"
21
22
  },
22
23
  "devDependencies": {
23
24
  "cross-env": "^7.0.3",
File without changes