aio-popup 6.2.0 → 6.3.0
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/index.d.ts +150 -145
- package/index.js +815 -802
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,802 +1,815 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
-
import { createRef, useEffect, useState, createContext, useContext, useRef } from 'react';
|
|
12
|
-
import * as ReactDOMServer from 'react-dom/server';
|
|
13
|
-
import ReactDOM from 'react-dom';
|
|
14
|
-
import anime from "animejs/lib/anime.es.js";
|
|
15
|
-
import $ from 'jquery';
|
|
16
|
-
import './index.css';
|
|
17
|
-
const CTX = createContext({});
|
|
18
|
-
function Align(p) {
|
|
19
|
-
let { modal, target, fitHorizontal, rtl, limitTo } = p;
|
|
20
|
-
const bodyWidth = window.innerWidth, bodyHeight = window.innerHeight;
|
|
21
|
-
let pageLimit = { left: 0, top: 0, bottom: bodyHeight, right: bodyWidth, width: bodyWidth, height: bodyHeight };
|
|
22
|
-
let targetLimit = getBound(target[0]);
|
|
23
|
-
let domLimit = getBound(modal[0]);
|
|
24
|
-
targetLimit = Object.assign({}, targetLimit);
|
|
25
|
-
domLimit = Object.assign({}, domLimit);
|
|
26
|
-
let overflowY;
|
|
27
|
-
domLimit.top = targetLimit.bottom;
|
|
28
|
-
domLimit.bottom = domLimit.top + domLimit.height;
|
|
29
|
-
if (fitHorizontal) {
|
|
30
|
-
domLimit.width = targetLimit.width;
|
|
31
|
-
domLimit.left = targetLimit.left;
|
|
32
|
-
domLimit.right = targetLimit.left + targetLimit.width;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
if (limitTo) {
|
|
36
|
-
let elem = modal.parents(limitTo);
|
|
37
|
-
if (elem.length) {
|
|
38
|
-
pageLimit = getBound(elem[0]);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
//اگر راست به چپ باید باشد
|
|
42
|
-
if (rtl) {
|
|
43
|
-
//راست المان را با راست هدف ست کن
|
|
44
|
-
domLimit.right = targetLimit.right;
|
|
45
|
-
//چپ المان را بروز رسانی کن
|
|
46
|
-
domLimit.left = domLimit.right - domLimit.width;
|
|
47
|
-
//اگر المان از سمت چپ از صفحه بیرون زد سمت چپ المان را با سمت چپ صفحه ست کن
|
|
48
|
-
if (domLimit.left < pageLimit.left) {
|
|
49
|
-
domLimit.left = pageLimit.left;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
//چپ المان را با چپ هدف ست کن
|
|
54
|
-
domLimit.left = targetLimit.left;
|
|
55
|
-
//راست المان را بروز رسانی کن
|
|
56
|
-
domLimit.right = domLimit.left + domLimit.width;
|
|
57
|
-
//اگر المان از سمت راست صفحه بیرون زد سمت چپ المان را با پهنای المان ست کن
|
|
58
|
-
if (domLimit.right > pageLimit.right) {
|
|
59
|
-
domLimit.left = pageLimit.right - domLimit.width;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
//اگر المان از سمت پایین صفحه بیرون زد
|
|
64
|
-
if (domLimit.bottom > pageLimit.bottom) {
|
|
65
|
-
if (domLimit.height > targetLimit.top - pageLimit.top) {
|
|
66
|
-
domLimit.top = pageLimit.bottom - domLimit.height;
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
domLimit.top = targetLimit.top - domLimit.height;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
domLimit.top = targetLimit.bottom;
|
|
74
|
-
}
|
|
75
|
-
if (domLimit.height > pageLimit.height) {
|
|
76
|
-
domLimit.top = pageLimit.top;
|
|
77
|
-
domLimit.height = pageLimit.height;
|
|
78
|
-
overflowY = 'auto';
|
|
79
|
-
}
|
|
80
|
-
return { left: domLimit.left, top: domLimit.top, width: domLimit.width, overflowY, maxWidth: pageLimit.width };
|
|
81
|
-
}
|
|
82
|
-
const CloseIcon = () => {
|
|
83
|
-
return (_jsx("svg", { viewBox: "0 0 24 24", role: "presentation", style: { width: '1.2rem', height: '1.2rem' }, children: _jsx("path", { d: "M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z", style: { fill: 'currentcolor' } }) }));
|
|
84
|
-
};
|
|
85
|
-
function AddToAttrs(attrs, p) {
|
|
86
|
-
attrs = attrs || {};
|
|
87
|
-
let { style } = p;
|
|
88
|
-
let attrClassName = attrs.className ? attrs.className.split(' ') : [];
|
|
89
|
-
let className = p.className ? (Array.isArray(p.className) ? p.className : p.className.split(' ')) : [];
|
|
90
|
-
let classNames = [...attrClassName, ...className.filter((o) => !!o)];
|
|
91
|
-
let newClassName = classNames.length ? classNames.join(' ') : undefined;
|
|
92
|
-
let newStyle = Object.assign(Object.assign({}, attrs.style), style);
|
|
93
|
-
return Object.assign(Object.assign(Object.assign({}, attrs), { className: newClassName, style: newStyle }), p.attrs);
|
|
94
|
-
}
|
|
95
|
-
const usePopup = (props) => {
|
|
96
|
-
let [modals, setModals] = useState([]);
|
|
97
|
-
const promptTexts = useRef({});
|
|
98
|
-
let modalsRef = useRef(modals);
|
|
99
|
-
modalsRef.current = modals;
|
|
100
|
-
const getModals = () => modalsRef.current;
|
|
101
|
-
const [snackebarItems, setSnackebarItems] = useState([]);
|
|
102
|
-
const snackebarItemsRef = useRef(snackebarItems);
|
|
103
|
-
snackebarItemsRef.current = snackebarItems;
|
|
104
|
-
const [highlight, setHighlight] = useState();
|
|
105
|
-
const addModal = (o) => {
|
|
106
|
-
if (o.id === undefined) {
|
|
107
|
-
o.id = 'popup' + Math.round(Math.random() * 1000000);
|
|
108
|
-
}
|
|
109
|
-
let newModal = o;
|
|
110
|
-
setModals(prevModals => {
|
|
111
|
-
let newModals = prevModals.filter(({ id }) => id !== o.id);
|
|
112
|
-
return [...newModals, newModal];
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
const removeModal = (arg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
116
|
-
if (typeof arg !== 'string') {
|
|
117
|
-
arg = 'last';
|
|
118
|
-
}
|
|
119
|
-
if (arg === 'all') {
|
|
120
|
-
setModals([]);
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (!modalsRef.current.length) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
if (arg === 'last') {
|
|
127
|
-
arg = modalsRef.current[modalsRef.current.length - 1].id;
|
|
128
|
-
}
|
|
129
|
-
let modal = modalsRef.current.find((o) => o.id === arg);
|
|
130
|
-
if (!modal) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
$(`[data-id=${arg}]`).addClass('not-mounted');
|
|
134
|
-
setTimeout(() => {
|
|
135
|
-
if (modal && typeof modal.onClose === 'function') {
|
|
136
|
-
modal.onClose();
|
|
137
|
-
}
|
|
138
|
-
setModals(prevModals => prevModals.filter((o) => o.id !== arg));
|
|
139
|
-
}, 300);
|
|
140
|
-
});
|
|
141
|
-
const addSnackebar = (item) => {
|
|
142
|
-
let items = snackebarItemsRef.current;
|
|
143
|
-
let newItems = [...items, Object.assign(Object.assign({}, item), { id: 'a' + Math.round(Math.random() * 1000000000) })];
|
|
144
|
-
setSnackebarItems(newItems);
|
|
145
|
-
};
|
|
146
|
-
const removeSnackebar = (id) => {
|
|
147
|
-
const items = snackebarItemsRef.current;
|
|
148
|
-
const item = items.find((o) => o.id === id);
|
|
149
|
-
if (!item || item.onClose === false) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
let newItems = items.filter((o, i) => o.id !== id);
|
|
153
|
-
setSnackebarItems(newItems);
|
|
154
|
-
if (typeof item.onClose === 'function') {
|
|
155
|
-
item.onClose();
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
const addAlert = (obj) => Alert(Object.assign({ rtl: props === null || props === void 0 ? void 0 : props.rtl }, obj));
|
|
159
|
-
const addHighlight = (highlight) => setHighlight(highlight);
|
|
160
|
-
const removeHighlight = () => setHighlight(undefined);
|
|
161
|
-
const addConfirm = (obj) => {
|
|
162
|
-
let { title, subtitle, text, submitText = 'Yes', canselText = 'No', onSubmit, onCansel = () => { }, setAttrs = () => { return {}; } } = obj;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
};
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
let style =
|
|
299
|
-
let
|
|
300
|
-
return
|
|
301
|
-
}
|
|
302
|
-
function
|
|
303
|
-
if (!
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
let
|
|
307
|
-
if (
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
}
|
|
351
|
-
function
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
if (
|
|
356
|
-
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
return
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
}
|
|
383
|
-
if (
|
|
384
|
-
return
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
let
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}
|
|
469
|
-
let
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
};
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
};
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
const
|
|
515
|
-
const {
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
let
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
let
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
this.
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
};
|
|
781
|
-
this.
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { createRef, useEffect, useState, createContext, useContext, useRef } from 'react';
|
|
12
|
+
import * as ReactDOMServer from 'react-dom/server';
|
|
13
|
+
import ReactDOM from 'react-dom';
|
|
14
|
+
import anime from "animejs/lib/anime.es.js";
|
|
15
|
+
import $ from 'jquery';
|
|
16
|
+
import './index.css';
|
|
17
|
+
const CTX = createContext({});
|
|
18
|
+
function Align(p) {
|
|
19
|
+
let { modal, target, fitHorizontal, rtl, limitTo } = p;
|
|
20
|
+
const bodyWidth = window.innerWidth, bodyHeight = window.innerHeight;
|
|
21
|
+
let pageLimit = { left: 0, top: 0, bottom: bodyHeight, right: bodyWidth, width: bodyWidth, height: bodyHeight };
|
|
22
|
+
let targetLimit = getBound(target[0]);
|
|
23
|
+
let domLimit = getBound(modal[0]);
|
|
24
|
+
targetLimit = Object.assign({}, targetLimit);
|
|
25
|
+
domLimit = Object.assign({}, domLimit);
|
|
26
|
+
let overflowY;
|
|
27
|
+
domLimit.top = targetLimit.bottom;
|
|
28
|
+
domLimit.bottom = domLimit.top + domLimit.height;
|
|
29
|
+
if (fitHorizontal) {
|
|
30
|
+
domLimit.width = targetLimit.width;
|
|
31
|
+
domLimit.left = targetLimit.left;
|
|
32
|
+
domLimit.right = targetLimit.left + targetLimit.width;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
if (limitTo) {
|
|
36
|
+
let elem = modal.parents(limitTo);
|
|
37
|
+
if (elem.length) {
|
|
38
|
+
pageLimit = getBound(elem[0]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//اگر راست به چپ باید باشد
|
|
42
|
+
if (rtl) {
|
|
43
|
+
//راست المان را با راست هدف ست کن
|
|
44
|
+
domLimit.right = targetLimit.right;
|
|
45
|
+
//چپ المان را بروز رسانی کن
|
|
46
|
+
domLimit.left = domLimit.right - domLimit.width;
|
|
47
|
+
//اگر المان از سمت چپ از صفحه بیرون زد سمت چپ المان را با سمت چپ صفحه ست کن
|
|
48
|
+
if (domLimit.left < pageLimit.left) {
|
|
49
|
+
domLimit.left = pageLimit.left;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
//چپ المان را با چپ هدف ست کن
|
|
54
|
+
domLimit.left = targetLimit.left;
|
|
55
|
+
//راست المان را بروز رسانی کن
|
|
56
|
+
domLimit.right = domLimit.left + domLimit.width;
|
|
57
|
+
//اگر المان از سمت راست صفحه بیرون زد سمت چپ المان را با پهنای المان ست کن
|
|
58
|
+
if (domLimit.right > pageLimit.right) {
|
|
59
|
+
domLimit.left = pageLimit.right - domLimit.width;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//اگر المان از سمت پایین صفحه بیرون زد
|
|
64
|
+
if (domLimit.bottom > pageLimit.bottom) {
|
|
65
|
+
if (domLimit.height > targetLimit.top - pageLimit.top) {
|
|
66
|
+
domLimit.top = pageLimit.bottom - domLimit.height;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
domLimit.top = targetLimit.top - domLimit.height;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
domLimit.top = targetLimit.bottom;
|
|
74
|
+
}
|
|
75
|
+
if (domLimit.height > pageLimit.height) {
|
|
76
|
+
domLimit.top = pageLimit.top;
|
|
77
|
+
domLimit.height = pageLimit.height;
|
|
78
|
+
overflowY = 'auto';
|
|
79
|
+
}
|
|
80
|
+
return { left: domLimit.left, top: domLimit.top, width: domLimit.width, overflowY, maxWidth: pageLimit.width };
|
|
81
|
+
}
|
|
82
|
+
const CloseIcon = () => {
|
|
83
|
+
return (_jsx("svg", { viewBox: "0 0 24 24", role: "presentation", style: { width: '1.2rem', height: '1.2rem' }, children: _jsx("path", { d: "M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z", style: { fill: 'currentcolor' } }) }));
|
|
84
|
+
};
|
|
85
|
+
function AddToAttrs(attrs, p) {
|
|
86
|
+
attrs = attrs || {};
|
|
87
|
+
let { style } = p;
|
|
88
|
+
let attrClassName = attrs.className ? attrs.className.split(' ') : [];
|
|
89
|
+
let className = p.className ? (Array.isArray(p.className) ? p.className : p.className.split(' ')) : [];
|
|
90
|
+
let classNames = [...attrClassName, ...className.filter((o) => !!o)];
|
|
91
|
+
let newClassName = classNames.length ? classNames.join(' ') : undefined;
|
|
92
|
+
let newStyle = Object.assign(Object.assign({}, attrs.style), style);
|
|
93
|
+
return Object.assign(Object.assign(Object.assign({}, attrs), { className: newClassName, style: newStyle }), p.attrs);
|
|
94
|
+
}
|
|
95
|
+
const usePopup = (props) => {
|
|
96
|
+
let [modals, setModals] = useState([]);
|
|
97
|
+
const promptTexts = useRef({});
|
|
98
|
+
let modalsRef = useRef(modals);
|
|
99
|
+
modalsRef.current = modals;
|
|
100
|
+
const getModals = () => modalsRef.current;
|
|
101
|
+
const [snackebarItems, setSnackebarItems] = useState([]);
|
|
102
|
+
const snackebarItemsRef = useRef(snackebarItems);
|
|
103
|
+
snackebarItemsRef.current = snackebarItems;
|
|
104
|
+
const [highlight, setHighlight] = useState();
|
|
105
|
+
const addModal = (o) => {
|
|
106
|
+
if (o.id === undefined) {
|
|
107
|
+
o.id = 'popup' + Math.round(Math.random() * 1000000);
|
|
108
|
+
}
|
|
109
|
+
let newModal = o;
|
|
110
|
+
setModals(prevModals => {
|
|
111
|
+
let newModals = prevModals.filter(({ id }) => id !== o.id);
|
|
112
|
+
return [...newModals, newModal];
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
const removeModal = (arg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
116
|
+
if (typeof arg !== 'string') {
|
|
117
|
+
arg = 'last';
|
|
118
|
+
}
|
|
119
|
+
if (arg === 'all') {
|
|
120
|
+
setModals([]);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (!modalsRef.current.length) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (arg === 'last') {
|
|
127
|
+
arg = modalsRef.current[modalsRef.current.length - 1].id;
|
|
128
|
+
}
|
|
129
|
+
let modal = modalsRef.current.find((o) => o.id === arg);
|
|
130
|
+
if (!modal) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
$(`[data-id=${arg}]`).addClass('not-mounted');
|
|
134
|
+
setTimeout(() => {
|
|
135
|
+
if (modal && typeof modal.onClose === 'function') {
|
|
136
|
+
modal.onClose();
|
|
137
|
+
}
|
|
138
|
+
setModals(prevModals => prevModals.filter((o) => o.id !== arg));
|
|
139
|
+
}, 300);
|
|
140
|
+
});
|
|
141
|
+
const addSnackebar = (item) => {
|
|
142
|
+
let items = snackebarItemsRef.current;
|
|
143
|
+
let newItems = [...items, Object.assign(Object.assign({}, item), { id: 'a' + Math.round(Math.random() * 1000000000) })];
|
|
144
|
+
setSnackebarItems(newItems);
|
|
145
|
+
};
|
|
146
|
+
const removeSnackebar = (id) => {
|
|
147
|
+
const items = snackebarItemsRef.current;
|
|
148
|
+
const item = items.find((o) => o.id === id);
|
|
149
|
+
if (!item || item.onClose === false) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
let newItems = items.filter((o, i) => o.id !== id);
|
|
153
|
+
setSnackebarItems(newItems);
|
|
154
|
+
if (typeof item.onClose === 'function') {
|
|
155
|
+
item.onClose();
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
const addAlert = (obj) => Alert(Object.assign({ rtl: props === null || props === void 0 ? void 0 : props.rtl }, obj));
|
|
159
|
+
const addHighlight = (highlight) => setHighlight(highlight);
|
|
160
|
+
const removeHighlight = () => setHighlight(undefined);
|
|
161
|
+
const addConfirm = (obj) => {
|
|
162
|
+
let { title, subtitle, text, submitText = 'Yes', canselText = 'No', onSubmit, onCansel = () => { }, setAttrs = () => { return {}; } } = obj;
|
|
163
|
+
const submitAttrs = AddToAttrs(obj.submitAttrs, {
|
|
164
|
+
className: 'active', attrs: {
|
|
165
|
+
onClick: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
166
|
+
if (!onSubmit) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
let res = yield onSubmit();
|
|
170
|
+
if (res !== false) {
|
|
171
|
+
removeModal();
|
|
172
|
+
}
|
|
173
|
+
}),
|
|
174
|
+
type: 'button'
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
const canselAttrs = AddToAttrs(obj.canselAttrs, {
|
|
178
|
+
attrs: {
|
|
179
|
+
onClick: () => { onCansel(); removeModal(); },
|
|
180
|
+
type: 'button'
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
let config = {
|
|
184
|
+
position: 'center', header: { title, subtitle }, body: _jsx(_Fragment, { children: text }),
|
|
185
|
+
setAttrs: (key) => {
|
|
186
|
+
let attrs = setAttrs(key);
|
|
187
|
+
return key === 'modal' ? AddToAttrs(attrs, { className: 'aio-popup-confirm' }) : attrs;
|
|
188
|
+
},
|
|
189
|
+
footer: (_jsxs(_Fragment, { children: [_jsx("button", Object.assign({}, canselAttrs, { children: canselText })), _jsx("button", Object.assign({}, submitAttrs, { children: submitText }))] }))
|
|
190
|
+
};
|
|
191
|
+
addModal(config);
|
|
192
|
+
};
|
|
193
|
+
const addPrompt = (obj) => {
|
|
194
|
+
const id = 'a' + (Math.round(Math.random() * 100000));
|
|
195
|
+
let { title, text = '', subtitle, submitText = 'Submit', canselText = 'close', onSubmit, onCansel = () => { }, setAttrs = () => { return {}; } } = obj;
|
|
196
|
+
const submitAttrs = AddToAttrs(obj.submitAttrs, {
|
|
197
|
+
className: 'active', attrs: {
|
|
198
|
+
onClick: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
199
|
+
if (!onSubmit) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const value = promptTexts.current[id];
|
|
203
|
+
let res = yield onSubmit(value);
|
|
204
|
+
if (res !== false) {
|
|
205
|
+
removeModal();
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
const newPromptTexts = {};
|
|
209
|
+
for (let prop in promptTexts.current) {
|
|
210
|
+
if (prop !== id) {
|
|
211
|
+
newPromptTexts[prop] = promptTexts.current[prop];
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
promptTexts.current = newPromptTexts;
|
|
215
|
+
}
|
|
216
|
+
}),
|
|
217
|
+
type: 'button'
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
const canselAttrs = AddToAttrs(obj.canselAttrs, { attrs: {
|
|
221
|
+
onClick: () => { onCansel(); removeModal(); },
|
|
222
|
+
type: 'button'
|
|
223
|
+
} });
|
|
224
|
+
let config = {
|
|
225
|
+
position: 'center', header: { title, subtitle },
|
|
226
|
+
setAttrs: (key) => {
|
|
227
|
+
let attrs = setAttrs(key);
|
|
228
|
+
return key === 'modal' ? AddToAttrs(attrs, { className: 'aio-popup-prompt' }) : attrs;
|
|
229
|
+
},
|
|
230
|
+
body: _jsx(Prompt, { change: (value) => promptTexts.current = Object.assign(Object.assign({}, promptTexts.current), { [id]: value }), placeholder: text }),
|
|
231
|
+
footer: (_jsxs(_Fragment, { children: [_jsx("button", Object.assign({}, canselAttrs, { children: canselText })), _jsx("button", Object.assign({}, submitAttrs, { children: submitText }))] }))
|
|
232
|
+
};
|
|
233
|
+
addModal(config);
|
|
234
|
+
};
|
|
235
|
+
const getContext = () => {
|
|
236
|
+
return {
|
|
237
|
+
rtl: !!props && !!props.rtl,
|
|
238
|
+
snackebarItems: snackebarItemsRef.current,
|
|
239
|
+
removeSnackebar, removeModal
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
const render = (caller) => {
|
|
243
|
+
return (_jsxs(CTX.Provider, { value: getContext(), children: [modalsRef.current.map((modal, i) => {
|
|
244
|
+
return (_jsx(Popup, { modal: modal, isLast: i === modalsRef.current.length - 1, renderCaller: caller }, modal.id));
|
|
245
|
+
}), snackebarItems.map((item, i) => _jsx(SnackebarItem, { item: item, index: i }, item.id)), !!highlight && _jsx(Highlight, { highlight: highlight })] }));
|
|
246
|
+
};
|
|
247
|
+
const portal = () => ReactDOM.createPortal(render(), document.body);
|
|
248
|
+
return { addAlert, addSnackebar, removeModal, addModal, getModals, addHighlight, removeHighlight, render, addConfirm, addPrompt, portal };
|
|
249
|
+
};
|
|
250
|
+
export default usePopup;
|
|
251
|
+
const Prompt = ({ change, placeholder }) => {
|
|
252
|
+
const [text, setText] = useState('');
|
|
253
|
+
return (_jsx("textarea", { placeholder: placeholder, value: text, onChange: (e) => { const value = e.target.value; setText(value); change(value); } }));
|
|
254
|
+
};
|
|
255
|
+
const POPUPCTX = createContext({});
|
|
256
|
+
const Popup = ({ modal, isLast, renderCaller }) => {
|
|
257
|
+
const mainContext = useContext(CTX);
|
|
258
|
+
let { setAttrs = () => { return {}; }, id, position = 'fullscreen', getTarget } = modal;
|
|
259
|
+
let [temp] = useState({ dom: createRef(), backdropDom: createRef(), dui: undefined });
|
|
260
|
+
let [popoverStyle, setPopoverStyle] = useState({});
|
|
261
|
+
let modalMouseDown = useRef(false);
|
|
262
|
+
//bar taraf kardane moshkele mozakhrafe click rooye backdrop ke az har ja mouse ro roosh vel mikoni modal baste mishe
|
|
263
|
+
const isModalMouseDown = () => modalMouseDown.current;
|
|
264
|
+
let [state, setState] = useState(modal.state);
|
|
265
|
+
let attrs = setAttrs('modal') || {};
|
|
266
|
+
const firstMount = useRef(false);
|
|
267
|
+
useEffect(() => () => { $(window).unbind('click', handleBackClick); });
|
|
268
|
+
useEffect(() => {
|
|
269
|
+
if (position === 'popover') {
|
|
270
|
+
setPopoverStyle(getPopoverStyle());
|
|
271
|
+
}
|
|
272
|
+
if (getTarget) {
|
|
273
|
+
temp.dui = 'a' + (Math.round(Math.random() * 10000000));
|
|
274
|
+
let target = getTarget();
|
|
275
|
+
target.attr('data-id', temp.dui);
|
|
276
|
+
}
|
|
277
|
+
setTimeout(() => {
|
|
278
|
+
let popup = $(temp.dom.current);
|
|
279
|
+
popup.removeClass('not-mounted');
|
|
280
|
+
$(temp.backdropDom.current).removeClass('not-mounted');
|
|
281
|
+
popup.focus();
|
|
282
|
+
}, 0);
|
|
283
|
+
$(window).unbind('click', handleBackClick);
|
|
284
|
+
$(window).bind('click', handleBackClick);
|
|
285
|
+
}, []);
|
|
286
|
+
function handleBackClick(e) {
|
|
287
|
+
//در مود پاپاور اگر هر جایی غیر از اینپوت و پاپاور کلیک شد پاپاپ رو ببند
|
|
288
|
+
if (!temp.dui) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
let target = $(e.target);
|
|
292
|
+
if (position !== 'popover' || target.attr('data-id') === temp.dui || target.parents(`[data-id=${temp.dui}]`).length) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
mainContext.removeModal();
|
|
296
|
+
}
|
|
297
|
+
function getModalProps() {
|
|
298
|
+
let style = Object.assign(Object.assign({}, popoverStyle), attrs.style);
|
|
299
|
+
let ev = "ontouchstart" in document.documentElement ? 'onTouchStart' : 'onMouseDown';
|
|
300
|
+
return Object.assign(Object.assign({}, attrs), { ref: temp.dom, "data-id": modal.id, tabIndex: 0, onKeyDown, [ev]: mouseDown, className: getClassName(), style: Object.assign({}, style), onClick: (e) => { e.stopPropagation(); } });
|
|
301
|
+
}
|
|
302
|
+
function getPopoverStyle() {
|
|
303
|
+
if (!getTarget) {
|
|
304
|
+
return {};
|
|
305
|
+
}
|
|
306
|
+
let target = getTarget();
|
|
307
|
+
if (!target || !target.length) {
|
|
308
|
+
return {};
|
|
309
|
+
}
|
|
310
|
+
let p = { modal: $(temp.dom.current), target, fitHorizontal: modal.fitHorizontal, limitTo: modal.limitTo, attrs, rtl: mainContext.rtl };
|
|
311
|
+
let style = Align(p);
|
|
312
|
+
let res = Object.assign(Object.assign({}, style), { position: 'absolute' });
|
|
313
|
+
return res;
|
|
314
|
+
}
|
|
315
|
+
function onKeyDown(e) {
|
|
316
|
+
if (!isLast) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
let code = e.keyCode;
|
|
320
|
+
if (code === 27) {
|
|
321
|
+
mainContext.removeModal();
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function mouseUp() {
|
|
325
|
+
setTimeout(() => modalMouseDown.current = false, 0);
|
|
326
|
+
}
|
|
327
|
+
function mouseDown(e) {
|
|
328
|
+
modalMouseDown.current = true;
|
|
329
|
+
$(window).unbind('mouseup', mouseUp);
|
|
330
|
+
$(window).bind('mouseup', mouseUp);
|
|
331
|
+
}
|
|
332
|
+
function getClassName() {
|
|
333
|
+
let className = 'aio-popup';
|
|
334
|
+
className += mainContext.rtl ? ' rtl' : ' ltr';
|
|
335
|
+
if (firstMount) {
|
|
336
|
+
className += ' not-mounted';
|
|
337
|
+
}
|
|
338
|
+
if (attrs.className) {
|
|
339
|
+
className += ' ' + attrs.className;
|
|
340
|
+
}
|
|
341
|
+
return className;
|
|
342
|
+
}
|
|
343
|
+
const getContext = () => ({ modal, isLast, state, setState, onKeyDown });
|
|
344
|
+
return (_jsx(POPUPCTX.Provider, { value: getContext(), children: _jsx(ModalBackdrop, { firstMount: !!firstMount, backdropDom: temp.backdropDom, isModalMouseDown: isModalMouseDown, children: _jsxs("div", Object.assign({}, getModalProps(), { children: [_jsx(ModalHeader, {}), _jsx(ModalBody, {}, modal.id), _jsx(ModalFooter, {})] }), modal.id) }, modal.id) }));
|
|
345
|
+
};
|
|
346
|
+
const ModalBackdrop = ({ children, firstMount, backdropDom, isModalMouseDown }) => {
|
|
347
|
+
const { removeModal, rtl } = useContext(CTX);
|
|
348
|
+
let { modal, onKeyDown } = useContext(POPUPCTX);
|
|
349
|
+
let { setAttrs = () => { return {}; }, id, position = 'fullscreen' } = modal;
|
|
350
|
+
const [attrs] = useState(setAttrs('backdrop') || {});
|
|
351
|
+
function backClick(e) {
|
|
352
|
+
if (isModalMouseDown()) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
if (e.target !== e.currentTarget) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
let target = $(e.target);
|
|
359
|
+
if (!target.hasClass('aio-popup-backdrop')) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
removeModal();
|
|
363
|
+
}
|
|
364
|
+
function getProps() {
|
|
365
|
+
let className = 'aio-popup-backdrop';
|
|
366
|
+
className += ` aio-popup-position-${position}`;
|
|
367
|
+
className += rtl ? ' rtl' : ' ltr';
|
|
368
|
+
if (firstMount) {
|
|
369
|
+
className += ' not-mounted';
|
|
370
|
+
}
|
|
371
|
+
return AddToAttrs(attrs, { className, attrs: { ref: backdropDom, onKeyDown, tabIndex: 0, ['data-id']: id, onClick: attrs.onClick ? attrs.onClick : backClick } });
|
|
372
|
+
}
|
|
373
|
+
return _jsx("div", Object.assign({}, getProps(), { children: children }));
|
|
374
|
+
};
|
|
375
|
+
const ModalHeader = () => {
|
|
376
|
+
const { removeModal } = useContext(CTX);
|
|
377
|
+
let { modal, state, setState } = useContext(POPUPCTX);
|
|
378
|
+
if (!modal.header) {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
let { setAttrs = () => { return {}; } } = modal;
|
|
382
|
+
let attrs = setAttrs('header') || {};
|
|
383
|
+
if (typeof modal.header === 'function') {
|
|
384
|
+
return modal.header({ removeModal: removeModal, state, setState });
|
|
385
|
+
}
|
|
386
|
+
if (typeof modal.header !== 'object') {
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
return (_jsxs("div", Object.assign({}, AddToAttrs(attrs, { className: 'aio-popup-header' }), { children: [_jsx(ModalHeaderElement, { type: 'before' }, 'before'), _jsx(ModalHeaderElement, { type: 'title' }, 'title'), _jsx(ModalHeaderElement, { type: 'after' }, 'after'), _jsx(ModalClose, {})] })));
|
|
390
|
+
};
|
|
391
|
+
const ModalHeaderElement = ({ type }) => {
|
|
392
|
+
let { modal } = useContext(POPUPCTX), { header } = modal;
|
|
393
|
+
if (typeof header === 'function' || !header) {
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
if (!header[type]) {
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
return _jsx("div", { className: `aio-popup-header-${type}`, "data-subtitle": type === 'title' ? header.subtitle : undefined, children: header[type] });
|
|
400
|
+
};
|
|
401
|
+
const ModalClose = () => {
|
|
402
|
+
const { removeModal } = useContext(CTX);
|
|
403
|
+
let { modal, state, setState } = useContext(POPUPCTX), { header } = modal;
|
|
404
|
+
if (typeof header === 'function' || !header) {
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
if (header.onClose === false) {
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
return _jsx("div", { className: `aio-popup-header-close`, onClick: (e) => {
|
|
411
|
+
e.stopPropagation();
|
|
412
|
+
e.preventDefault();
|
|
413
|
+
if (typeof header.onClose === 'function') {
|
|
414
|
+
header.onClose({ state, setState });
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
removeModal(modal.id);
|
|
418
|
+
}
|
|
419
|
+
}, children: _jsx(CloseIcon, {}) });
|
|
420
|
+
};
|
|
421
|
+
const ModalBody = () => {
|
|
422
|
+
const { modal } = useContext(POPUPCTX);
|
|
423
|
+
let { body, setAttrs = () => { return {}; } } = modal;
|
|
424
|
+
let attrs = setAttrs('body') || {};
|
|
425
|
+
if (!body || body === null) {
|
|
426
|
+
return null;
|
|
427
|
+
}
|
|
428
|
+
return (_jsx("div", Object.assign({}, AddToAttrs(attrs, { className: 'aio-popup-body aio-popup-scroll' }), { children: body })));
|
|
429
|
+
};
|
|
430
|
+
const ModalFooter = () => {
|
|
431
|
+
const { modal } = useContext(POPUPCTX);
|
|
432
|
+
let { setAttrs = () => { return {}; }, footer } = modal;
|
|
433
|
+
if (!footer) {
|
|
434
|
+
return null;
|
|
435
|
+
}
|
|
436
|
+
let Attrs = setAttrs('footer') || {};
|
|
437
|
+
const attrs = AddToAttrs(Attrs, { className: 'aio-popup-footer' });
|
|
438
|
+
return _jsx("div", Object.assign({}, attrs, { children: footer }));
|
|
439
|
+
};
|
|
440
|
+
const SBCTX = createContext({});
|
|
441
|
+
const SnackebarItem = (props) => {
|
|
442
|
+
const mainContext = useContext(CTX);
|
|
443
|
+
let { item } = props;
|
|
444
|
+
let { time = 8, id, align = ['right', 'top'] } = item;
|
|
445
|
+
if (align[1] !== 'top' && align[1] !== 'bottom') {
|
|
446
|
+
align[1] = 'top';
|
|
447
|
+
}
|
|
448
|
+
if (align[0] !== 'left' && align[0] !== 'right' && align[0] !== 'center') {
|
|
449
|
+
align[0] = 'right';
|
|
450
|
+
}
|
|
451
|
+
let [mounted, setMounted] = useState(false);
|
|
452
|
+
useEffect(() => {
|
|
453
|
+
setTimeout(() => setMounted(true), 0);
|
|
454
|
+
setTimeout(() => remove(), time * 1000);
|
|
455
|
+
}, []);
|
|
456
|
+
function remove() {
|
|
457
|
+
setMounted(false);
|
|
458
|
+
setTimeout(() => mainContext.removeSnackebar(id), 200);
|
|
459
|
+
}
|
|
460
|
+
const getSvg = (type) => { return type === 'error' || type === 'warning' || type === 'info' ? _jsx(InfoSvg, {}) : _jsx(SuccessSvg, {}); };
|
|
461
|
+
const getContext = () => {
|
|
462
|
+
return { mainContext, remove, item: Object.assign(Object.assign({}, props.item), { time, align }), index: props.index, mounted, getSvg };
|
|
463
|
+
};
|
|
464
|
+
return (_jsx(SBCTX.Provider, { value: getContext(), children: _jsx(SnackebarContainer, {}) }));
|
|
465
|
+
};
|
|
466
|
+
const SnackebarContainer = () => {
|
|
467
|
+
const { mainContext, mounted, index, item, remove } = useContext(SBCTX);
|
|
468
|
+
const { rtl } = mainContext;
|
|
469
|
+
let { onClose, align = ['right', 'top'] } = item;
|
|
470
|
+
function getOffsetStyle(index) {
|
|
471
|
+
let els = $('.aio-popup-snackebar-item-container'), sum = { top: 12, bottom: 12 };
|
|
472
|
+
for (let i = 0; i < index; i++) {
|
|
473
|
+
let dom = els.eq(i);
|
|
474
|
+
let height = dom.height() + 6;
|
|
475
|
+
let va = dom.attr('data-vertical-align');
|
|
476
|
+
sum[va] += height;
|
|
477
|
+
}
|
|
478
|
+
return {
|
|
479
|
+
[align[1] === 'top' ? 'top' : 'bottom']: sum[align[1]]
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
let className = 'aio-popup-snackebar-item-container';
|
|
483
|
+
className += ` aio-popup-snackebar-item-container-horizontal-align-${align[0]}`;
|
|
484
|
+
if (mounted) {
|
|
485
|
+
className += ' mounted';
|
|
486
|
+
}
|
|
487
|
+
if (rtl) {
|
|
488
|
+
className += ' rtl';
|
|
489
|
+
}
|
|
490
|
+
let style = getOffsetStyle(index);
|
|
491
|
+
let p = { 'data-vertical-align': align[1], className, style, onClick: onClose === false ? undefined : () => remove() };
|
|
492
|
+
return _jsx("div", Object.assign({}, p, { children: _jsx(SnackebarCard, {}) }));
|
|
493
|
+
};
|
|
494
|
+
const SnackebarCard = () => {
|
|
495
|
+
const { item } = useContext(SBCTX);
|
|
496
|
+
let { type, attrs = {} } = item;
|
|
497
|
+
let className = 'aio-popup-snackebar-item';
|
|
498
|
+
className += ` aio-popup-snackebar-item-${type}`;
|
|
499
|
+
if (attrs.className) {
|
|
500
|
+
className += ` ${attrs.className}`;
|
|
501
|
+
}
|
|
502
|
+
let p = Object.assign(Object.assign({}, attrs), { className, style: attrs.style });
|
|
503
|
+
return (_jsxs("div", Object.assign({}, p, { children: [_jsx(SnackebarIcon, {}), _jsx(SnackebarText, {}), _jsx(SnackebarAction, {}), _jsx(SnackebarBar, {})] })));
|
|
504
|
+
};
|
|
505
|
+
const SnackebarIcon = () => {
|
|
506
|
+
const { getSvg, item } = useContext(SBCTX);
|
|
507
|
+
return _jsx("div", { className: `aio-popup-snackebar-item-icon`, children: !!item.icon ? item.icon : getSvg(item.type) });
|
|
508
|
+
};
|
|
509
|
+
const SnackebarText = () => {
|
|
510
|
+
const { item } = useContext(SBCTX);
|
|
511
|
+
return (_jsxs("div", { className: 'aio-popup-snackebar-item-text', children: [_jsx("div", { className: 'aio-popup-snackebar-item-uptext', children: item.text }), !!item.subtext && _jsx("div", { className: 'aio-popup-snackebar-item-subtext', children: item.subtext })] }));
|
|
512
|
+
};
|
|
513
|
+
const SnackebarAction = () => {
|
|
514
|
+
const { item, remove } = useContext(SBCTX);
|
|
515
|
+
const { action } = item;
|
|
516
|
+
if (!action || !action.text) {
|
|
517
|
+
return null;
|
|
518
|
+
}
|
|
519
|
+
let p = {
|
|
520
|
+
className: 'aio-popup-snackebar-item-action',
|
|
521
|
+
onClick: (e) => { e.stopPropagation(); if (action) {
|
|
522
|
+
action.onClick();
|
|
523
|
+
} remove(); }
|
|
524
|
+
};
|
|
525
|
+
return (_jsx("button", Object.assign({}, p, { children: action.text })));
|
|
526
|
+
};
|
|
527
|
+
const SnackebarBar = () => {
|
|
528
|
+
const { item } = useContext(SBCTX);
|
|
529
|
+
return _jsx("div", { className: 'aio-popup-snackebar-bar', style: { transition: `${item.time || 8}s linear` } });
|
|
530
|
+
};
|
|
531
|
+
export function Alert(props) {
|
|
532
|
+
let { icon, type = '', title = '', text = '', time = 10, className, closeText = 'Close', onClose, rtl } = props;
|
|
533
|
+
let $$ = {
|
|
534
|
+
id: '',
|
|
535
|
+
time: 0,
|
|
536
|
+
getId() {
|
|
537
|
+
return 'aa' + Math.round((Math.random() * 100000000));
|
|
538
|
+
},
|
|
539
|
+
getBarRender() {
|
|
540
|
+
return `<div class='aio-popup-time-bar' style="width:${$$.time}%;"></div>`;
|
|
541
|
+
},
|
|
542
|
+
updateBarRender() {
|
|
543
|
+
$(`.aio-popup-alert-container.${$$.id} .aio-popup-time`).html($$.getBarRender());
|
|
544
|
+
},
|
|
545
|
+
getRender() {
|
|
546
|
+
return (`
|
|
547
|
+
<div class='aio-popup-alert-container not-mounted ${$$.id} aio-popup-alert-container-center${!!className ? ` ${className}` : ''}'>
|
|
548
|
+
<div class='aio-popup-alert aio-popup-alert-${type}'>
|
|
549
|
+
<div class='aio-popup-alert-header'>${$$.getIcon()}</div>
|
|
550
|
+
<div class='aio-popup-alert-body aio-popup-scroll'>
|
|
551
|
+
<div class='aio-popup-alert-title'>${ReactDOMServer.renderToStaticMarkup(title)}</div>
|
|
552
|
+
<div class='aio-popup-alert-text' style="text-align:${rtl ? 'right' : 'left'}">${text}</div>
|
|
553
|
+
</div>
|
|
554
|
+
<div class='aio-popup-alert-footer'>
|
|
555
|
+
<button class='aio-popup-alert-close ${$$.id}'>${closeText}</button>
|
|
556
|
+
</div>
|
|
557
|
+
<div class='aio-popup-time'></div>
|
|
558
|
+
</div>
|
|
559
|
+
</div>
|
|
560
|
+
`);
|
|
561
|
+
},
|
|
562
|
+
close() {
|
|
563
|
+
$$.toggleClass(false);
|
|
564
|
+
setTimeout(() => {
|
|
565
|
+
if (typeof onClose === 'function') {
|
|
566
|
+
onClose();
|
|
567
|
+
}
|
|
568
|
+
if (onClose === false) {
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
$('.' + $$.id).remove();
|
|
572
|
+
}, 200);
|
|
573
|
+
},
|
|
574
|
+
getIcon() {
|
|
575
|
+
if (icon === false) {
|
|
576
|
+
return '';
|
|
577
|
+
}
|
|
578
|
+
return icon || {
|
|
579
|
+
error: (`<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z"></path></svg>`),
|
|
580
|
+
warning: (`<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M12,2L1,21H23M12,6L19.53,19H4.47M11,10V14H13V10M11,16V18H13V16"></path></svg>`),
|
|
581
|
+
info: (`<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z"></path></svg>`),
|
|
582
|
+
success: (`<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M12 20C7.59 20 4 16.41 4 12S7.59 4 12 4 20 7.59 20 12 16.41 20 12 20M16.59 7.58L10 14.17L7.41 11.59L6 13L10 17L18 9L16.59 7.58Z"></path></svg>`)
|
|
583
|
+
}[type] || '';
|
|
584
|
+
},
|
|
585
|
+
startTimer() {
|
|
586
|
+
setTimeout(() => {
|
|
587
|
+
if ($$.time >= 100) {
|
|
588
|
+
$$.time = 100;
|
|
589
|
+
$$.close();
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
$$.time += 2;
|
|
593
|
+
$$.updateBarRender();
|
|
594
|
+
$$.startTimer();
|
|
595
|
+
}, time / 50 * 1000);
|
|
596
|
+
},
|
|
597
|
+
toggleClass(mount) {
|
|
598
|
+
let dom = $(`.${$$.id}`);
|
|
599
|
+
if (mount) {
|
|
600
|
+
setTimeout(() => dom.removeClass('not-mounted'), 0);
|
|
601
|
+
}
|
|
602
|
+
else {
|
|
603
|
+
dom.addClass('not-mounted');
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
render() {
|
|
607
|
+
$('body').append($$.getRender());
|
|
608
|
+
$('button.' + $$.id).off('click', $$.close);
|
|
609
|
+
$('button.' + $$.id).on('click', $$.close);
|
|
610
|
+
$$.toggleClass(true);
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
$$.id = $$.getId();
|
|
614
|
+
$$.render();
|
|
615
|
+
if (time) {
|
|
616
|
+
$$.startTimer();
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
const Highlight = ({ highlight }) => {
|
|
620
|
+
const [limit, setLimit] = useState({ Left: 0, Top: 0, Width: 0, Height: 0, TopSpace: 0, BottomSpace: 0 });
|
|
621
|
+
const limitRef = useRef(limit);
|
|
622
|
+
limitRef.current = limit;
|
|
623
|
+
useEffect(() => {
|
|
624
|
+
setTimeout(() => {
|
|
625
|
+
try {
|
|
626
|
+
const { dom, duration = 1200 } = highlight;
|
|
627
|
+
dom[0].scrollIntoView();
|
|
628
|
+
let newLimit = getHLLimit(highlight);
|
|
629
|
+
let easing = getEasing(highlight);
|
|
630
|
+
let obj = Object.assign(Object.assign({}, newLimit), { targets: [Object.assign({}, limitRef.current)], duration, update: (p) => {
|
|
631
|
+
const { animatables } = p;
|
|
632
|
+
setLimit(Object.assign({}, animatables[0].target));
|
|
633
|
+
} });
|
|
634
|
+
if (easing) {
|
|
635
|
+
obj.easing = easing;
|
|
636
|
+
}
|
|
637
|
+
anime(obj);
|
|
638
|
+
}
|
|
639
|
+
catch (_a) {
|
|
640
|
+
alert(`aio-highlighter error => connot find dom`);
|
|
641
|
+
}
|
|
642
|
+
}, 0);
|
|
643
|
+
});
|
|
644
|
+
function getArrowIcon(props) {
|
|
645
|
+
return (_jsx("svg", Object.assign({ version: "1.1", id: "Layer_1", xmlns: "http://www.w3.org/2000/svg", x: "0px", y: "0px", viewBox: "0 0 512 512" }, props, { children: _jsxs("g", { children: [_jsx("path", { d: "M242.1,45.2c7.7-7.7,20.2-7.7,27.8-0.1l0.1,0.1l236.3,236.3c7.7,7.7,7.7,20.2,0,27.9c-7.7,7.7-20.2,7.7-27.9,0\r\n L256,86.9L33.7,309.3c-7.7,7.7-20.2,7.7-27.9,0c-7.7-7.7-7.7-20.2,0-27.9L242.1,45.2z" }), _jsx("path", { d: "M242.1,202.7c7.7-7.7,20.2-7.7,27.8-0.1l0.1,0.1L506.2,439c7.7,7.7,7.7,20.2,0,27.9c-7.7,7.7-20.2,7.7-27.9,0\r\n L256,244.5L33.7,466.9c-7.7,7.7-20.2,7.7-27.9,0c-7.7-7.7-7.7-20.2,0-27.9L242.1,202.7z" })] }) })));
|
|
646
|
+
}
|
|
647
|
+
function getArrow(dir, left, width) {
|
|
648
|
+
let center = left + width / 2, Left = center - 12;
|
|
649
|
+
let style = { position: 'absolute', height: 24, width: 24, left: Left };
|
|
650
|
+
let props = { width: 24, height: 24, style, className: `aio-popup-highlight-arrow-${dir}` };
|
|
651
|
+
return (_jsx("div", { className: "aio-popup-highlight-arrow", children: getArrowIcon(props) }));
|
|
652
|
+
}
|
|
653
|
+
function getHtml(dir) {
|
|
654
|
+
if (!highlight.html) {
|
|
655
|
+
return '';
|
|
656
|
+
}
|
|
657
|
+
let column;
|
|
658
|
+
let html = highlight.html || '';
|
|
659
|
+
let space = _jsx("div", { className: "aio-popup-highlight-space" });
|
|
660
|
+
let content = _jsx("div", { className: "aio-popup-highlight-html", children: html });
|
|
661
|
+
let arrow = getArrow(dir, limitRef.current.Left, limitRef.current.Width);
|
|
662
|
+
if (dir === 'top') {
|
|
663
|
+
column = _jsxs(_Fragment, { children: [space, content, arrow] });
|
|
664
|
+
}
|
|
665
|
+
else {
|
|
666
|
+
column = _jsxs(_Fragment, { children: [arrow, content, space] });
|
|
667
|
+
}
|
|
668
|
+
return _jsx("div", { className: "aio-popup-highlight-html-container", children: column });
|
|
669
|
+
}
|
|
670
|
+
function click() {
|
|
671
|
+
if (highlight.mouseAccess) {
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
if (highlight.onClick) {
|
|
675
|
+
highlight.onClick();
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
function vMask_node(type) {
|
|
679
|
+
let html = '', size = 0, className = 'aio-popup-highlight-mask';
|
|
680
|
+
let dir = type === 'top' || type === 'bottom' ? 'height' : 'width';
|
|
681
|
+
let limit = limitRef.current;
|
|
682
|
+
if (type === 'top') {
|
|
683
|
+
size = limit.Top;
|
|
684
|
+
if (limit.TopSpace > limit.BottomSpace) {
|
|
685
|
+
html = getHtml('top');
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
else if (type === 'bottom') {
|
|
689
|
+
className += ' aio-popup-highlight-mask-flex';
|
|
690
|
+
if (limit.TopSpace <= limit.BottomSpace) {
|
|
691
|
+
html = getHtml('bottom');
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
else if (type === 'left') {
|
|
695
|
+
size = limit.Left;
|
|
696
|
+
}
|
|
697
|
+
else {
|
|
698
|
+
className += ' aio-popup-highlight-mask-flex';
|
|
699
|
+
}
|
|
700
|
+
return (_jsx("div", { className: className, style: { [dir]: size }, onClick: () => click(), children: html }));
|
|
701
|
+
}
|
|
702
|
+
function focus_node() {
|
|
703
|
+
const cls1 = "aio-popup-highlight-focus-container", cls2 = 'aio-popup-highlight-focus';
|
|
704
|
+
return (_jsx("div", { style: { width: limit.Width }, className: cls1, onClick: click, children: _jsx("div", { className: cls2 }) }));
|
|
705
|
+
}
|
|
706
|
+
function main_node() {
|
|
707
|
+
return _jsxs("div", { className: "aio-popup-highlight-main", style: { height: limit.Height }, children: [vMask_node('left'), focus_node(), vMask_node('right')] });
|
|
708
|
+
}
|
|
709
|
+
function getStyle() { return { pointerEvents: highlight.mouseAccess ? 'none' : 'all' }; }
|
|
710
|
+
const attrs = AddToAttrs(highlight.attrs, { className: 'aio-popup-highlight', style: getStyle() });
|
|
711
|
+
return (_jsxs("div", Object.assign({}, attrs, { children: [vMask_node('top'), main_node(), vMask_node('bottom')] })));
|
|
712
|
+
};
|
|
713
|
+
function getHLLimit(highlight) {
|
|
714
|
+
const { padding = 6, dom } = highlight;
|
|
715
|
+
let offset = dom.offset();
|
|
716
|
+
let left = offset.left - window.pageXOffset;
|
|
717
|
+
let top = offset.top - window.pageYOffset;
|
|
718
|
+
let pageHeight = window.innerHeight;
|
|
719
|
+
let width = dom.outerWidth();
|
|
720
|
+
let height = dom.outerHeight();
|
|
721
|
+
let Top = top - 1 * padding;
|
|
722
|
+
let Left = left - 1 * padding;
|
|
723
|
+
let Width = width + 2 * padding;
|
|
724
|
+
let Height = height + 2 * padding;
|
|
725
|
+
let TopSpace = top;
|
|
726
|
+
let BottomSpace = pageHeight - (top + height);
|
|
727
|
+
let res = { Left, Top, Width, Height, TopSpace, BottomSpace };
|
|
728
|
+
return res;
|
|
729
|
+
}
|
|
730
|
+
function getEasing(highlight) {
|
|
731
|
+
const { easing } = highlight;
|
|
732
|
+
var easingNames = [
|
|
733
|
+
'linear',
|
|
734
|
+
'easeInQuad',
|
|
735
|
+
'easeInSine',
|
|
736
|
+
'easeInCirc',
|
|
737
|
+
'easeInBack',
|
|
738
|
+
'easeOutQuad',
|
|
739
|
+
'easeOutSine',
|
|
740
|
+
'easeOutCirc',
|
|
741
|
+
'easeInOutQuad',
|
|
742
|
+
'easeInOutSine',
|
|
743
|
+
'easeInOutBack',
|
|
744
|
+
'easeOutBounce', //27
|
|
745
|
+
];
|
|
746
|
+
if (typeof easing === 'number') {
|
|
747
|
+
let res = easingNames[easing];
|
|
748
|
+
return res || easingNames[0];
|
|
749
|
+
}
|
|
750
|
+
return easing;
|
|
751
|
+
}
|
|
752
|
+
const InfoSvg = () => {
|
|
753
|
+
const d = "M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z";
|
|
754
|
+
return (_jsx("svg", { viewBox: "0 0 24 24", role: "presentation", style: { width: '1.2rem', height: '1.2rem' }, children: _jsx("path", { d: d, style: { fill: 'currentcolor' } }) }));
|
|
755
|
+
};
|
|
756
|
+
const SuccessSvg = () => {
|
|
757
|
+
const d = "M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M12 20C7.59 20 4 16.41 4 12S7.59 4 12 4 20 7.59 20 12 16.41 20 12 20M16.59 7.58L10 14.17L7.41 11.59L6 13L10 17L18 9L16.59 7.58Z";
|
|
758
|
+
return (_jsx("svg", { viewBox: "0 0 24 24", role: "presentation", style: { width: '1.2rem', height: '1.2rem' }, children: _jsx("path", { d: d, style: { fill: 'currentcolor' } }) }));
|
|
759
|
+
};
|
|
760
|
+
function getBound(dom) {
|
|
761
|
+
try {
|
|
762
|
+
const res = dom.getBoundingClientRect();
|
|
763
|
+
return { width: res.width, height: res.height, left: res.left, top: res.top, bottom: res.bottom, right: res.right };
|
|
764
|
+
}
|
|
765
|
+
catch (_a) {
|
|
766
|
+
return { width: 0, height: 0, left: 0, top: 0, bottom: 0, right: 0 };
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
export class Loading {
|
|
770
|
+
constructor(loader) {
|
|
771
|
+
this.loader = '0';
|
|
772
|
+
this.getLoader_0 = () => {
|
|
773
|
+
return (`
|
|
774
|
+
<div class="aio-loading-container-0">
|
|
775
|
+
<div class="aio-loading-0">
|
|
776
|
+
${new Array(5).fill(0).map((o, i) => this.getLoaderItem_0(`0.${i}`)).join(' ')}
|
|
777
|
+
</div>
|
|
778
|
+
</div>
|
|
779
|
+
`);
|
|
780
|
+
};
|
|
781
|
+
this.getLoaderItem_0 = (ease) => {
|
|
782
|
+
return `<div class="aio-loading-item-0" style="animation: 1s ease-in-out ${ease}s infinite normal none running aioloading0;"></div>`;
|
|
783
|
+
};
|
|
784
|
+
this.getLoader = (id) => {
|
|
785
|
+
let content = '';
|
|
786
|
+
if (this.loader === '0') {
|
|
787
|
+
content = this.getLoader_0();
|
|
788
|
+
}
|
|
789
|
+
else if (typeof this.loader === 'string') {
|
|
790
|
+
content = this.loader;
|
|
791
|
+
}
|
|
792
|
+
return (`<div class="aio-loading" id="aio-loading-${id}">${content}</div>`);
|
|
793
|
+
};
|
|
794
|
+
this.show = (id, parentSelector) => {
|
|
795
|
+
parentSelector = parentSelector || 'body';
|
|
796
|
+
let loadingStr = this.getLoader(id);
|
|
797
|
+
let parent = document.querySelector(parentSelector);
|
|
798
|
+
if (parent) {
|
|
799
|
+
parent.insertAdjacentHTML('beforeend', loadingStr);
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
this.hide = (id) => {
|
|
803
|
+
let loadingDom = document.getElementById('aio-loading-' + id);
|
|
804
|
+
if (!loadingDom) {
|
|
805
|
+
loadingDom = document.querySelector('.aio-loading');
|
|
806
|
+
}
|
|
807
|
+
if (loadingDom) {
|
|
808
|
+
loadingDom.remove();
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
if (typeof loader === 'string') {
|
|
812
|
+
this.loader = loader;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
}
|