samandesk 1.0.24 → 1.0.25
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/saman-desk.js +150 -96
- package/dist/saman-desk.umd.cjs +1 -1
- package/dist/src/data.d.ts +4 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/interoperation.d.ts +18 -3
- package/package.json +6 -5
package/dist/saman-desk.js
CHANGED
|
@@ -1,102 +1,139 @@
|
|
|
1
|
-
let
|
|
2
|
-
const
|
|
3
|
-
let
|
|
4
|
-
|
|
1
|
+
let token;
|
|
2
|
+
const frame = document.createElement("iframe");
|
|
3
|
+
let theme;
|
|
4
|
+
let color;
|
|
5
|
+
let language;
|
|
6
|
+
let linkHandler = (link) => window.open(link, "_blank", "noopener");
|
|
7
|
+
const backdrop = document.createElement("div");
|
|
8
|
+
const run = {
|
|
5
9
|
count: 0,
|
|
6
10
|
promises: {}
|
|
7
11
|
};
|
|
8
|
-
function
|
|
9
|
-
return
|
|
12
|
+
function getRun() {
|
|
13
|
+
return run;
|
|
10
14
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
15
|
+
function setToken(newToken) {
|
|
16
|
+
token = newToken;
|
|
13
17
|
}
|
|
14
|
-
function
|
|
15
|
-
return
|
|
18
|
+
function getToken() {
|
|
19
|
+
return token;
|
|
16
20
|
}
|
|
17
|
-
function
|
|
18
|
-
|
|
21
|
+
function clearFrame() {
|
|
22
|
+
frame.src = "";
|
|
19
23
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
24
|
+
function setFrameSrc(src) {
|
|
25
|
+
frame.src = src;
|
|
22
26
|
}
|
|
23
|
-
function
|
|
24
|
-
return
|
|
27
|
+
function getFrame() {
|
|
28
|
+
return frame;
|
|
25
29
|
}
|
|
26
|
-
function
|
|
27
|
-
return { theme
|
|
30
|
+
function getTheme() {
|
|
31
|
+
return { theme, color };
|
|
28
32
|
}
|
|
29
|
-
function
|
|
30
|
-
return { language
|
|
33
|
+
function getLanguage() {
|
|
34
|
+
return { language };
|
|
31
35
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
36
|
+
function setTheme(newTheme) {
|
|
37
|
+
theme = newTheme.darkMode;
|
|
38
|
+
color = newTheme.color;
|
|
34
39
|
}
|
|
35
|
-
function
|
|
36
|
-
|
|
40
|
+
function setLanguage(newLanguage) {
|
|
41
|
+
language = newLanguage;
|
|
37
42
|
}
|
|
38
|
-
function
|
|
39
|
-
return
|
|
43
|
+
function getBackdrop() {
|
|
44
|
+
return backdrop;
|
|
40
45
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return C;
|
|
46
|
+
function setOpenLinkFn(fn) {
|
|
47
|
+
if (fn) linkHandler = fn;
|
|
44
48
|
}
|
|
45
|
-
function
|
|
46
|
-
return
|
|
49
|
+
function getOpenLinkFn() {
|
|
50
|
+
return linkHandler;
|
|
47
51
|
}
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
const readyEvent = new Event("ready");
|
|
53
|
+
const openEvent = new Event("open");
|
|
54
|
+
const closeEvent = new Event("close");
|
|
55
|
+
function getReadyEvent() {
|
|
56
|
+
return readyEvent;
|
|
50
57
|
}
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
function getOpenEvent() {
|
|
59
|
+
return openEvent;
|
|
60
|
+
}
|
|
61
|
+
function getCloseEvent() {
|
|
62
|
+
return closeEvent;
|
|
63
|
+
}
|
|
64
|
+
function handleEvents(interoperation) {
|
|
65
|
+
window.addEventListener("message", (event) => {
|
|
66
|
+
if (!event.data.from || event.data.from !== "SamanDesk") return;
|
|
67
|
+
let handledByInterOperation = false;
|
|
68
|
+
console.log(`message from (${event.origin})`, event);
|
|
57
69
|
try {
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
interoperation[event.data.action](event.data);
|
|
71
|
+
handledByInterOperation = true;
|
|
72
|
+
} catch (err) {
|
|
60
73
|
console.error("error while run event action");
|
|
61
74
|
}
|
|
62
|
-
const
|
|
63
|
-
|
|
75
|
+
const data = event.data;
|
|
76
|
+
const id = data.id;
|
|
77
|
+
const run2 = getRun();
|
|
78
|
+
if (id in run2.promises) {
|
|
79
|
+
run2.promises[id](data);
|
|
80
|
+
delete run2.promises[id];
|
|
81
|
+
} else if (!handledByInterOperation) {
|
|
82
|
+
console.error("Message from outside of frame is invalid");
|
|
83
|
+
}
|
|
64
84
|
});
|
|
65
85
|
}
|
|
66
|
-
function
|
|
67
|
-
var
|
|
68
|
-
const
|
|
69
|
-
|
|
86
|
+
function resolveRun(id, data, action) {
|
|
87
|
+
var _a;
|
|
88
|
+
const postData = { from: "SamanDesk", action, data, id };
|
|
89
|
+
const frame2 = getFrame();
|
|
90
|
+
(_a = frame2.contentWindow) == null ? void 0 : _a.postMessage(postData, "*");
|
|
70
91
|
}
|
|
71
|
-
class
|
|
92
|
+
class InterOperation {
|
|
72
93
|
async init() {
|
|
73
|
-
|
|
94
|
+
handleEvents(this);
|
|
74
95
|
}
|
|
75
96
|
/** توکن را از میزبان دریافت کرده و آن را ذخیره میکند. سپس به میزبان اعلام میکند که آمادهی ادامهی کار است */
|
|
76
|
-
setToken(
|
|
77
|
-
|
|
97
|
+
setToken(data) {
|
|
98
|
+
setToken(data.data.token);
|
|
99
|
+
clearFrame();
|
|
100
|
+
window.dispatchEvent(getReadyEvent());
|
|
78
101
|
}
|
|
79
102
|
/** بستن کتابخانه */
|
|
80
103
|
close() {
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
document.body.removeChild(
|
|
104
|
+
clearFrame();
|
|
105
|
+
const backdrop2 = getBackdrop();
|
|
106
|
+
document.body.removeChild(backdrop2);
|
|
107
|
+
backdrop2.onclick = null;
|
|
108
|
+
document.body.removeChild(getFrame());
|
|
109
|
+
window.dispatchEvent(getCloseEvent());
|
|
84
110
|
}
|
|
85
111
|
/** اطلاعات کتابخانه را به بیرون اطلاع میدهد */
|
|
86
|
-
getConfig(
|
|
87
|
-
const
|
|
88
|
-
|
|
112
|
+
getConfig(data) {
|
|
113
|
+
const themeData = getTheme();
|
|
114
|
+
const languageData = getLanguage();
|
|
115
|
+
resolveRun(data.id, { color: themeData.color, theme: themeData.theme, language: languageData.language }, data.action);
|
|
116
|
+
}
|
|
117
|
+
/** لینک موردنظر را به وسیلهی تابع از پیش تعریفشده باز میکند */
|
|
118
|
+
openLink(data) {
|
|
119
|
+
getOpenLinkFn()(data.data.link);
|
|
89
120
|
}
|
|
90
121
|
}
|
|
91
|
-
const
|
|
92
|
-
class
|
|
122
|
+
const SITE_URL = "https://samandesk.com";
|
|
123
|
+
class SamanDesk {
|
|
93
124
|
/**
|
|
94
125
|
* این تابع در ابتدا مقدار verifiedToken را دریافت کرده و سپس مقدار token را دریافت و سپس آن را ذخیره میکند
|
|
95
126
|
*/
|
|
96
|
-
async init(
|
|
97
|
-
this.interoperation = new
|
|
98
|
-
|
|
99
|
-
|
|
127
|
+
async init(verifiedToken) {
|
|
128
|
+
this.interoperation = new InterOperation();
|
|
129
|
+
this.interoperation.init();
|
|
130
|
+
const frame2 = getFrame();
|
|
131
|
+
const backdrop2 = getBackdrop();
|
|
132
|
+
setFrameSrc(`${SITE_URL}/setup-interoperation/${verifiedToken}`);
|
|
133
|
+
frame2.width = "0";
|
|
134
|
+
frame2.style.width = "0";
|
|
135
|
+
document.body.appendChild(backdrop2);
|
|
136
|
+
document.body.appendChild(frame2);
|
|
100
137
|
}
|
|
101
138
|
/**
|
|
102
139
|
* استایل مربوط به آیفریم را تنظیم میکند
|
|
@@ -104,10 +141,12 @@ class F {
|
|
|
104
141
|
* @param fullScreen - تمام صفحه باز شود یا خیر
|
|
105
142
|
*
|
|
106
143
|
*/
|
|
107
|
-
setStyle(
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
144
|
+
setStyle(fullScreen) {
|
|
145
|
+
const frame2 = getFrame();
|
|
146
|
+
const backdrop2 = getBackdrop();
|
|
147
|
+
frame2.style.position = "fixed";
|
|
148
|
+
frame2.style.zIndex = "1000";
|
|
149
|
+
const backdropStyles = {
|
|
111
150
|
position: "fixed",
|
|
112
151
|
top: "0",
|
|
113
152
|
bottom: "0",
|
|
@@ -116,46 +155,61 @@ class F {
|
|
|
116
155
|
backgroundColor: "rgba(0,0,0,0.5)",
|
|
117
156
|
zIndex: "1000"
|
|
118
157
|
};
|
|
119
|
-
Object.assign(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
158
|
+
Object.assign(backdrop2.style, backdropStyles);
|
|
159
|
+
if (fullScreen) {
|
|
160
|
+
Object.assign(frame2.style, {
|
|
161
|
+
bottom: "0",
|
|
162
|
+
left: "0",
|
|
163
|
+
top: "0",
|
|
164
|
+
right: "0",
|
|
165
|
+
width: "100%"
|
|
166
|
+
});
|
|
167
|
+
frame2.width = "100%";
|
|
168
|
+
frame2.height = "100%";
|
|
169
|
+
} else {
|
|
170
|
+
Object.assign(frame2.style, {
|
|
171
|
+
top: "50%",
|
|
172
|
+
left: "50%",
|
|
173
|
+
transform: "translate(-50%, -50%)",
|
|
174
|
+
width: "100%",
|
|
175
|
+
maxWidth: "500px",
|
|
176
|
+
boxShadow: "0px 0px 100px 0px rgba(0,0,0,0.48)",
|
|
177
|
+
borderRadius: "24px",
|
|
178
|
+
height: "100%",
|
|
179
|
+
maxHeight: "660px"
|
|
180
|
+
});
|
|
181
|
+
}
|
|
136
182
|
}
|
|
137
183
|
/**
|
|
138
184
|
* این تابع آیفریم را باز میکند.
|
|
139
185
|
*/
|
|
140
|
-
open(
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
186
|
+
open(config) {
|
|
187
|
+
const frame2 = getFrame();
|
|
188
|
+
const backdrop2 = getBackdrop();
|
|
189
|
+
setTheme({
|
|
190
|
+
darkMode: config.theme.darkMode ?? "light",
|
|
191
|
+
color: config.theme.color ?? "default"
|
|
192
|
+
});
|
|
193
|
+
setLanguage(config.language ?? "fa");
|
|
194
|
+
const src = config.link || `${SITE_URL}/department-selection?token=${getToken()}`;
|
|
195
|
+
setFrameSrc(src);
|
|
196
|
+
setOpenLinkFn(config.linkHandler);
|
|
197
|
+
this.setStyle(config.fullScreen);
|
|
198
|
+
document.body.appendChild(backdrop2);
|
|
199
|
+
document.body.appendChild(frame2);
|
|
200
|
+
backdrop2.onclick = () => {
|
|
148
201
|
this.close();
|
|
149
|
-
}
|
|
202
|
+
};
|
|
203
|
+
window.dispatchEvent(getOpenEvent());
|
|
150
204
|
}
|
|
151
205
|
/**
|
|
152
206
|
* بستن کتابخانه
|
|
153
207
|
*/
|
|
154
208
|
close() {
|
|
155
|
-
var
|
|
156
|
-
(
|
|
209
|
+
var _a;
|
|
210
|
+
(_a = this.interoperation) == null ? void 0 : _a.close();
|
|
157
211
|
}
|
|
158
212
|
}
|
|
159
213
|
export {
|
|
160
|
-
|
|
214
|
+
SamanDesk
|
|
161
215
|
};
|
package/dist/saman-desk.umd.cjs
CHANGED
|
@@ -1 +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 c(){o.src=""}function l(e){o.src=e}function p(){return o}function m(){return d}const h=new Event("ready"),u=new Event("open"),f=new Event("close");function g(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(){g(this)}setToken(e){var o;o=e.data.token,t=o,c(),window.dispatchEvent(h)}close(){c();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:a};!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){s(e.data.link)}}const b="https://samandesk.com";e.SamanDesk=class{async init(e){this.interoperation=new y,this.interoperation.init();const t=p(),o=m();l(`${b}/setup-interoperation/${e}`),t.width="0",t.style.width="0",document.body.appendChild(o),document.body.appendChild(t)}setStyle(e){const t=p(),o=m();t.style.position="fixed",t.style.zIndex="1000";Object.assign(o.style,{position:"fixed",top:"0",bottom:"0",left:"0",right:"0",backgroundColor:"rgba(0,0,0,0.5)",zIndex:"1000"}),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 o=p(),d=m();var r,c;r={darkMode:e.theme.darkMode??"light",color:e.theme.color??"default"},n=r.darkMode,i=r.color,c=e.language??"fa",a=c;var h;l(e.link||`${b}/department-selection?token=${t}`),(h=e.linkHandler)&&(s=h),this.setStyle(e.fullScreen),document.body.appendChild(d),document.body.appendChild(o),d.onclick=()=>{this.close()},window.dispatchEvent(u)}close(){var e;null==(e=this.interoperation)||e.close()}},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/src/data.d.ts
CHANGED
|
@@ -42,4 +42,8 @@ export declare function setTheme(newTheme: ProjectTheme): void;
|
|
|
42
42
|
export declare function setLanguage(newLanguage: string): void;
|
|
43
43
|
/** عنصر بکدراپ را برمیگرداند */
|
|
44
44
|
export declare function getBackdrop(): HTMLDivElement;
|
|
45
|
+
/** تابع مدیریتکنندهی لینکها را ست میکند */
|
|
46
|
+
export declare function setOpenLinkFn(fn?: (link: string) => void): void;
|
|
47
|
+
/** تابع مدیریتکنندهی لینکها را برمیگرداند */
|
|
48
|
+
export declare function getOpenLinkFn(): (link: string) => void;
|
|
45
49
|
export {};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FunctionKeys } from 'utility-types';
|
|
2
|
+
type MessageData<T = {}> = {
|
|
3
|
+
/** شناسه داده */
|
|
4
|
+
id: number;
|
|
5
|
+
/** تابعی که داده برای آن ارسال شده است */
|
|
6
|
+
action: string;
|
|
7
|
+
/** داده موردنظر */
|
|
8
|
+
data: T;
|
|
9
|
+
};
|
|
2
10
|
/**
|
|
3
11
|
* این تابع برای فراخوانی متدهاییست که مقداری بر نمیگردانند
|
|
4
12
|
*/
|
|
@@ -10,9 +18,16 @@ export declare function run<A extends FunctionKeys<InterOperation>>(action: A, d
|
|
|
10
18
|
export declare class InterOperation {
|
|
11
19
|
init(): Promise<void>;
|
|
12
20
|
/** توکن را از میزبان دریافت کرده و آن را ذخیره میکند. سپس به میزبان اعلام میکند که آمادهی ادامهی کار است */
|
|
13
|
-
setToken(data:
|
|
21
|
+
setToken(data: MessageData<{
|
|
22
|
+
token: string;
|
|
23
|
+
}>): void;
|
|
14
24
|
/** بستن کتابخانه */
|
|
15
25
|
close(): void;
|
|
16
26
|
/** اطلاعات کتابخانه را به بیرون اطلاع میدهد */
|
|
17
|
-
getConfig(data:
|
|
27
|
+
getConfig(data: MessageData): void;
|
|
28
|
+
/** لینک موردنظر را به وسیلهی تابع از پیش تعریفشده باز میکند */
|
|
29
|
+
openLink(data: MessageData<{
|
|
30
|
+
link: string;
|
|
31
|
+
}>): void;
|
|
18
32
|
}
|
|
33
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "samandesk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.25",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -22,9 +22,10 @@
|
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"cross-env": "^7.0.3",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"vite
|
|
25
|
+
"terser": "^5.39.0",
|
|
26
|
+
"typescript": "^5.8.3",
|
|
27
|
+
"utility-types": "^3.11.0",
|
|
28
|
+
"vite": "^6.3.3",
|
|
29
|
+
"vite-plugin-dts": "^4.5.3"
|
|
29
30
|
}
|
|
30
31
|
}
|