aio-popup 3.3.0 → 4.0.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.css +47 -105
- package/index.d.ts +33 -64
- package/index.js +8 -1283
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,1290 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import $ from 'jquery';
|
|
6
|
-
import './index.css';
|
|
7
|
-
import { createElement as _createElement } from "react";
|
|
8
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
-
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
10
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
13
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
14
|
-
export default class AIOPopup {
|
|
15
|
-
constructor(obj) {
|
|
16
|
-
_defineProperty(this, "rtl", void 0);
|
|
17
|
-
_defineProperty(this, "render", void 0);
|
|
18
|
-
_defineProperty(this, "addModal", void 0);
|
|
19
|
-
_defineProperty(this, "addAlert", void 0);
|
|
20
|
-
_defineProperty(this, "removeModal", void 0);
|
|
21
|
-
_defineProperty(this, "_removeModal", void 0);
|
|
22
|
-
_defineProperty(this, "addSnackebar", void 0);
|
|
23
|
-
_defineProperty(this, "getModals", void 0);
|
|
24
|
-
_defineProperty(this, "_getModals", void 0);
|
|
25
|
-
_defineProperty(this, "addConfirm", void 0);
|
|
26
|
-
_defineProperty(this, "addPrompt", void 0);
|
|
27
|
-
_defineProperty(this, "popupId", void 0);
|
|
28
|
-
_defineProperty(this, "isRenderCalled", void 0);
|
|
29
|
-
let {
|
|
30
|
-
rtl = false,
|
|
31
|
-
id
|
|
32
|
-
} = obj || {};
|
|
33
|
-
this.isRenderCalled = false;
|
|
34
|
-
this.rtl = rtl;
|
|
35
|
-
this.addModal = () => {
|
|
36
|
-
alert('aio-popup error => missing call AIOPopup instance.render() in your project');
|
|
37
|
-
};
|
|
38
|
-
this.removeModal = () => {
|
|
39
|
-
alert('aio-popup error => missing call AIOPopup instance.render() in your project');
|
|
40
|
-
};
|
|
41
|
-
this.addSnackebar = () => {};
|
|
42
|
-
this._getModals = () => [];
|
|
43
|
-
this.render = () => {
|
|
44
|
-
this.isRenderCalled = true;
|
|
45
|
-
let popupsProps = {
|
|
46
|
-
rtl,
|
|
47
|
-
id,
|
|
48
|
-
getActions: ({
|
|
49
|
-
addModal,
|
|
50
|
-
removeModal,
|
|
51
|
-
getModals
|
|
52
|
-
}) => {
|
|
53
|
-
this.addModal = addModal;
|
|
54
|
-
this._removeModal = removeModal;
|
|
55
|
-
this._getModals = getModals;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
let snackebarProps = {
|
|
59
|
-
rtl,
|
|
60
|
-
getActions: ({
|
|
61
|
-
add
|
|
62
|
-
}) => {
|
|
63
|
-
this.addSnackebar = add;
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
67
|
-
children: [/*#__PURE__*/_createElement(Popups, {
|
|
68
|
-
...popupsProps,
|
|
69
|
-
key: id
|
|
70
|
-
}), /*#__PURE__*/_jsx(Snackebar, {
|
|
71
|
-
...snackebarProps
|
|
72
|
-
})]
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
this.addAlert = obj => Alert(obj);
|
|
76
|
-
this.removeModal = (arg, animate = true) => {
|
|
77
|
-
if (this._removeModal) {
|
|
78
|
-
this._removeModal(arg, animate);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
this.getModals = () => {
|
|
82
|
-
let res = this._getModals();
|
|
83
|
-
return Array.isArray(res) ? res : [];
|
|
84
|
-
};
|
|
85
|
-
this.addConfirm = obj => {
|
|
86
|
-
let {
|
|
87
|
-
title,
|
|
88
|
-
subtitle,
|
|
89
|
-
text,
|
|
90
|
-
submitText = 'Yes',
|
|
91
|
-
canselText = 'No',
|
|
92
|
-
onSubmit,
|
|
93
|
-
onCansel = () => {},
|
|
94
|
-
attrs = {}
|
|
95
|
-
} = obj;
|
|
96
|
-
let className = 'aio-popup-confirm';
|
|
97
|
-
if (attrs.className) {
|
|
98
|
-
className += ' ' + attrs.className;
|
|
99
|
-
}
|
|
100
|
-
let config = {
|
|
101
|
-
position: 'center',
|
|
102
|
-
attrs: {
|
|
103
|
-
...attrs,
|
|
104
|
-
className
|
|
105
|
-
},
|
|
106
|
-
header: {
|
|
107
|
-
title,
|
|
108
|
-
subtitle
|
|
109
|
-
},
|
|
110
|
-
backdrop: {
|
|
111
|
-
attrs: {
|
|
112
|
-
className: 'rsa-backdrop'
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
body: {
|
|
116
|
-
render: () => text
|
|
117
|
-
},
|
|
118
|
-
footer: {
|
|
119
|
-
buttons: [[canselText, {
|
|
120
|
-
onClick: () => {
|
|
121
|
-
onCansel();
|
|
122
|
-
this.removeModal();
|
|
123
|
-
}
|
|
124
|
-
}], [submitText, {
|
|
125
|
-
onClick: async () => {
|
|
126
|
-
if (!onSubmit) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
let res = await onSubmit();
|
|
130
|
-
if (res !== false) {
|
|
131
|
-
this.removeModal();
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
className: 'active'
|
|
135
|
-
}]]
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
this.addModal(config);
|
|
139
|
-
};
|
|
140
|
-
this.addPrompt = obj => {
|
|
141
|
-
let {
|
|
142
|
-
title,
|
|
143
|
-
subtitle,
|
|
144
|
-
text,
|
|
145
|
-
submitText = 'تایید',
|
|
146
|
-
canselText = 'بستن',
|
|
147
|
-
onSubmit,
|
|
148
|
-
onCansel = () => {},
|
|
149
|
-
attrs = {}
|
|
150
|
-
} = obj;
|
|
151
|
-
let className = 'aio-popup-prompt';
|
|
152
|
-
if (attrs.className) {
|
|
153
|
-
className += ' ' + attrs.className;
|
|
154
|
-
}
|
|
155
|
-
let config = {
|
|
156
|
-
position: 'center',
|
|
157
|
-
attrs: {
|
|
158
|
-
...attrs,
|
|
159
|
-
className
|
|
160
|
-
},
|
|
161
|
-
state: {
|
|
162
|
-
temp: ''
|
|
163
|
-
},
|
|
164
|
-
header: {
|
|
165
|
-
title,
|
|
166
|
-
subtitle
|
|
167
|
-
},
|
|
168
|
-
backdrop: {
|
|
169
|
-
attrs: {
|
|
170
|
-
className: 'rsa-backdrop'
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
body: {
|
|
174
|
-
render: ({
|
|
175
|
-
state,
|
|
176
|
-
setState
|
|
177
|
-
}) => {
|
|
178
|
-
return /*#__PURE__*/_jsx("textarea", {
|
|
179
|
-
placeholder: text,
|
|
180
|
-
value: state.temp,
|
|
181
|
-
onChange: e => {
|
|
182
|
-
if (setState) {
|
|
183
|
-
setState({
|
|
184
|
-
temp: e.target.value
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
footer: {
|
|
192
|
-
buttons: [[canselText, {
|
|
193
|
-
onClick: () => {
|
|
194
|
-
onCansel();
|
|
195
|
-
this.removeModal();
|
|
196
|
-
}
|
|
197
|
-
}], [submitText, p => {
|
|
198
|
-
let {
|
|
199
|
-
state,
|
|
200
|
-
setState
|
|
201
|
-
} = p || {};
|
|
202
|
-
return {
|
|
203
|
-
onClick: async p => {
|
|
204
|
-
if (!onSubmit) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
let {
|
|
208
|
-
state
|
|
209
|
-
} = p;
|
|
210
|
-
let res = await onSubmit(state.temp);
|
|
211
|
-
if (res !== false) {
|
|
212
|
-
this.removeModal();
|
|
213
|
-
} else {
|
|
214
|
-
setState({
|
|
215
|
-
temp: ''
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
},
|
|
219
|
-
disabled: !state.temp,
|
|
220
|
-
className: 'active'
|
|
221
|
-
};
|
|
222
|
-
}]]
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
this.addModal(config);
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
class Popups extends Component {
|
|
230
|
-
constructor(props) {
|
|
231
|
-
super(props);
|
|
232
|
-
this.state = {
|
|
233
|
-
modals: []
|
|
234
|
-
};
|
|
235
|
-
props.getActions({
|
|
236
|
-
addModal: this.addModal.bind(this),
|
|
237
|
-
removeModal: this.removeModal.bind(this),
|
|
238
|
-
getModals: () => this.state.modals
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
change(modals) {
|
|
242
|
-
let {
|
|
243
|
-
id
|
|
244
|
-
} = this.props;
|
|
245
|
-
let oldModals = [...this.state.modals];
|
|
246
|
-
let newModals = [...modals];
|
|
247
|
-
if (id === 'main') {
|
|
248
|
-
console.log('old modals', oldModals);
|
|
249
|
-
console.log('new modals', newModals);
|
|
250
|
-
}
|
|
251
|
-
this.setState({
|
|
252
|
-
modals: newModals
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
addModal(o) {
|
|
256
|
-
let {
|
|
257
|
-
modals
|
|
258
|
-
} = this.state;
|
|
259
|
-
if (o.id === undefined) {
|
|
260
|
-
o.id = 'popup' + Math.round(Math.random() * 1000000);
|
|
261
|
-
}
|
|
262
|
-
let newModals = modals.filter(({
|
|
263
|
-
id
|
|
264
|
-
}) => id !== o.id);
|
|
265
|
-
let newModal = o;
|
|
266
|
-
newModals.push(newModal);
|
|
267
|
-
this.change(newModals);
|
|
268
|
-
}
|
|
269
|
-
async removeModal(arg = 'last', animate = true) {
|
|
270
|
-
if (arg === 'all') {
|
|
271
|
-
this.setState({
|
|
272
|
-
modals: []
|
|
273
|
-
});
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
let {
|
|
277
|
-
modals
|
|
278
|
-
} = this.state;
|
|
279
|
-
if (!modals.length) {
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
if (arg === 'last') {
|
|
283
|
-
arg = modals[modals.length - 1].id;
|
|
284
|
-
}
|
|
285
|
-
let parentDom = $(`.aio-popup-backdrop[data-id=${arg}]`);
|
|
286
|
-
let dom = parentDom.find('.aio-popup');
|
|
287
|
-
parentDom.addClass('not-mounted');
|
|
288
|
-
dom.addClass('not-mounted');
|
|
289
|
-
setTimeout(() => {
|
|
290
|
-
let modal = modals.find(o => o.id === arg);
|
|
291
|
-
if (!modal) {
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
if (typeof modal.onClose === 'function') {
|
|
295
|
-
modal.onClose();
|
|
296
|
-
}
|
|
297
|
-
let newModals = modals.filter(o => o.id !== arg);
|
|
298
|
-
this.change(newModals);
|
|
299
|
-
}, animate ? 300 : 0);
|
|
300
|
-
}
|
|
301
|
-
getModals() {
|
|
302
|
-
let {
|
|
303
|
-
modals
|
|
304
|
-
} = this.state;
|
|
305
|
-
let {
|
|
306
|
-
rtl
|
|
307
|
-
} = this.props;
|
|
308
|
-
return modals.map((modal, i) => {
|
|
309
|
-
let props = {
|
|
310
|
-
modal,
|
|
311
|
-
index: i,
|
|
312
|
-
isLast: i === modals.length - 1,
|
|
313
|
-
rtl,
|
|
314
|
-
onClose: () => this.removeModal(modal.id),
|
|
315
|
-
removeModal: this.removeModal.bind(this) //use for remove lastModal by esc keyboard
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
return /*#__PURE__*/_jsx(Popup, {
|
|
319
|
-
...props
|
|
320
|
-
}, modal.id);
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
render() {
|
|
324
|
-
let {
|
|
325
|
-
modals
|
|
326
|
-
} = this.state;
|
|
327
|
-
let {
|
|
328
|
-
id
|
|
329
|
-
} = this.props;
|
|
330
|
-
if (id === 'main') {
|
|
331
|
-
console.log('render', modals.length);
|
|
332
|
-
}
|
|
333
|
-
if (!modals.length) {
|
|
334
|
-
return null;
|
|
335
|
-
}
|
|
336
|
-
let renderModals = this.getModals();
|
|
337
|
-
return /*#__PURE__*/_jsx(_Fragment, {
|
|
338
|
-
children: renderModals
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
function Popup(props) {
|
|
343
|
-
let {
|
|
344
|
-
modal,
|
|
345
|
-
rtl,
|
|
346
|
-
onClose,
|
|
347
|
-
isLast,
|
|
348
|
-
removeModal
|
|
349
|
-
} = props;
|
|
350
|
-
let {
|
|
351
|
-
attrs = {},
|
|
352
|
-
id,
|
|
353
|
-
backdrop = {},
|
|
354
|
-
footer,
|
|
355
|
-
header,
|
|
356
|
-
position = 'fullscreen',
|
|
357
|
-
body,
|
|
358
|
-
fitHorizontal,
|
|
359
|
-
getTarget,
|
|
360
|
-
pageSelector,
|
|
361
|
-
openRelatedTo,
|
|
362
|
-
fixStyle = o => o,
|
|
363
|
-
fitTo
|
|
364
|
-
} = modal;
|
|
365
|
-
let [temp] = useState({
|
|
366
|
-
dom: /*#__PURE__*/createRef(),
|
|
367
|
-
backdropDom: /*#__PURE__*/createRef(),
|
|
368
|
-
dui: undefined,
|
|
369
|
-
isDown: false,
|
|
370
|
-
isFirstMount: true
|
|
371
|
-
});
|
|
372
|
-
let [popoverStyle, setPopoverStyle] = useState({});
|
|
373
|
-
let [state, setState] = useState(modal.state);
|
|
374
|
-
async function close() {
|
|
375
|
-
onClose();
|
|
376
|
-
}
|
|
377
|
-
useEffect(() => {
|
|
378
|
-
return () => {
|
|
379
|
-
$(window).unbind('click', handleBackClick);
|
|
380
|
-
};
|
|
381
|
-
});
|
|
382
|
-
function updatePopoverStyle() {
|
|
383
|
-
if (position === 'popover') {
|
|
384
|
-
let ps = getPopoverStyle();
|
|
385
|
-
if (JSON.stringify(ps) !== JSON.stringify(popoverStyle)) {
|
|
386
|
-
setPopoverStyle(ps);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
useEffect(() => {
|
|
391
|
-
temp.isFirstMount = false;
|
|
392
|
-
setTimeout(() => {
|
|
393
|
-
setPopoverStyle(position === 'popover' ? getPopoverStyle() : {});
|
|
394
|
-
}, 0);
|
|
395
|
-
if (getTarget) {
|
|
396
|
-
temp.dui = 'a' + Math.round(Math.random() * 10000000);
|
|
397
|
-
let target = getTarget();
|
|
398
|
-
target.attr('data-uniq-id', temp.dui);
|
|
399
|
-
}
|
|
400
|
-
$(window).unbind('click', handleBackClick);
|
|
401
|
-
$(window).bind('click', handleBackClick);
|
|
402
|
-
}, []);
|
|
403
|
-
function handleBackClick(e) {
|
|
404
|
-
//در مود پاپاور اگر هر جایی غیر از اینپوت و پاپاور کلیک شد پاپاپ رو ببند
|
|
405
|
-
if (!temp.dui) {
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
let target = $(e.target);
|
|
409
|
-
if (position !== 'popover' || target.attr('data-uniq-id') === temp.dui || target.parents(`[data-uniq-id=${temp.dui}]`).length) {
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
close();
|
|
413
|
-
}
|
|
414
|
-
function header_node() {
|
|
415
|
-
if (typeof header !== 'object') {
|
|
416
|
-
return null;
|
|
417
|
-
}
|
|
418
|
-
return /*#__PURE__*/_jsx(ModalHeader, {
|
|
419
|
-
rtl: rtl,
|
|
420
|
-
header: header,
|
|
421
|
-
handleClose: () => close(),
|
|
422
|
-
state: state,
|
|
423
|
-
setState: value => setState(value)
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
function body_node() {
|
|
427
|
-
let p = {
|
|
428
|
-
body,
|
|
429
|
-
handleClose: () => close(),
|
|
430
|
-
state,
|
|
431
|
-
setState: value => setState(value),
|
|
432
|
-
updatePopoverStyle
|
|
433
|
-
};
|
|
434
|
-
return /*#__PURE__*/_jsx(ModalBody, {
|
|
435
|
-
...p
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
function footer_node() {
|
|
439
|
-
let handleClose = close;
|
|
440
|
-
let props = {
|
|
441
|
-
footer,
|
|
442
|
-
handleClose,
|
|
443
|
-
state,
|
|
444
|
-
setState
|
|
445
|
-
};
|
|
446
|
-
return /*#__PURE__*/_jsx(ModalFooter, {
|
|
447
|
-
...props
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
function getBackDropClassName() {
|
|
451
|
-
let className = 'aio-popup-backdrop';
|
|
452
|
-
if (temp.isFirstMount) {
|
|
453
|
-
className += ' not-mounted';
|
|
454
|
-
}
|
|
455
|
-
if (backdrop && backdrop.attrs && backdrop.attrs.className) {
|
|
456
|
-
className += ' ' + backdrop.attrs.className;
|
|
457
|
-
}
|
|
458
|
-
className += ` aio-popup-position-${position}`;
|
|
459
|
-
className += rtl ? ' rtl' : ' ltr';
|
|
460
|
-
return className;
|
|
461
|
-
}
|
|
462
|
-
function backClick(e) {
|
|
463
|
-
if (temp.isDown) {
|
|
464
|
-
return;
|
|
465
|
-
}
|
|
466
|
-
e.stopPropagation();
|
|
467
|
-
let target = $(e.target);
|
|
468
|
-
if (backdrop && backdrop.close === false) {
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
if (!target.hasClass('aio-popup-backdrop')) {
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
close();
|
|
475
|
-
}
|
|
476
|
-
function getPopoverStyle() {
|
|
477
|
-
if (!getTarget) {
|
|
478
|
-
return {};
|
|
479
|
-
}
|
|
480
|
-
let target = getTarget();
|
|
481
|
-
if (!target || !target.length) {
|
|
482
|
-
return {};
|
|
483
|
-
}
|
|
484
|
-
let popup = $(temp.dom.current);
|
|
485
|
-
let style = Align({
|
|
486
|
-
dom: popup,
|
|
487
|
-
target,
|
|
488
|
-
fitHorizontal,
|
|
489
|
-
fixStyle,
|
|
490
|
-
pageSelector,
|
|
491
|
-
openRelatedTo,
|
|
492
|
-
fitTo,
|
|
493
|
-
attrs,
|
|
494
|
-
rtl
|
|
495
|
-
});
|
|
496
|
-
return {
|
|
497
|
-
...style,
|
|
498
|
-
position: 'absolute'
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
function keyDown(e) {
|
|
502
|
-
if (!isLast) {
|
|
503
|
-
return;
|
|
504
|
-
}
|
|
505
|
-
let code = e.keyCode;
|
|
506
|
-
if (code === 27) {
|
|
507
|
-
removeModal();
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
function mouseUp() {
|
|
511
|
-
setTimeout(() => temp.isDown = false, 0);
|
|
512
|
-
}
|
|
513
|
-
function mouseDown(e) {
|
|
514
|
-
$(window).unbind('mouseup', mouseUp);
|
|
515
|
-
$(window).bind('mouseup', mouseUp);
|
|
516
|
-
temp.isDown = true;
|
|
517
|
-
}
|
|
518
|
-
function getClassName() {
|
|
519
|
-
let className = 'aio-popup';
|
|
520
|
-
if (temp.isFirstMount) {
|
|
521
|
-
className += ' not-mounted';
|
|
522
|
-
temp.isFirstMount = false;
|
|
523
|
-
}
|
|
524
|
-
className += rtl ? ' rtl' : ' ltr';
|
|
525
|
-
if (attrs.className) {
|
|
526
|
-
className += ' ' + attrs.className;
|
|
527
|
-
}
|
|
528
|
-
return className;
|
|
529
|
-
}
|
|
530
|
-
let backdropAttrs = backdrop ? backdrop.attrs : {};
|
|
531
|
-
let backdropProps = {
|
|
532
|
-
...backdropAttrs,
|
|
533
|
-
['data-id']: id,
|
|
534
|
-
className: getBackDropClassName(),
|
|
535
|
-
onClick: backdrop === false ? undefined : backdrop.close === false ? undefined : e => backClick(e)
|
|
536
|
-
};
|
|
537
|
-
let style = {
|
|
538
|
-
...popoverStyle,
|
|
539
|
-
...attrs.style,
|
|
540
|
-
flex: 'none'
|
|
541
|
-
};
|
|
542
|
-
let ev = "ontouchstart" in document.documentElement ? 'onTouchStart' : 'onMouseDown';
|
|
543
|
-
let p = {
|
|
544
|
-
...attrs,
|
|
545
|
-
ref: temp.dom,
|
|
546
|
-
"data-uniq-id": temp.dui,
|
|
547
|
-
[ev]: mouseDown,
|
|
548
|
-
className: getClassName(),
|
|
549
|
-
style: {
|
|
550
|
-
...style,
|
|
551
|
-
display: 'flex',
|
|
552
|
-
flexDirection: 'column'
|
|
553
|
-
}
|
|
554
|
-
};
|
|
555
|
-
return /*#__PURE__*/_jsx("div", {
|
|
556
|
-
...backdropProps,
|
|
557
|
-
ref: temp.backdropDom,
|
|
558
|
-
onKeyDown: keyDown,
|
|
559
|
-
tabIndex: 0,
|
|
560
|
-
children: /*#__PURE__*/_jsxs("div", {
|
|
561
|
-
...p,
|
|
562
|
-
children: [header_node(), " ", body_node(), " ", footer_node()]
|
|
563
|
-
})
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
function ModalHeader(props) {
|
|
567
|
-
let {
|
|
568
|
-
rtl,
|
|
569
|
-
header,
|
|
570
|
-
handleClose,
|
|
571
|
-
state,
|
|
572
|
-
setState
|
|
573
|
-
} = props;
|
|
574
|
-
if (typeof header !== 'object') {
|
|
575
|
-
return null;
|
|
576
|
-
}
|
|
577
|
-
let {
|
|
578
|
-
title,
|
|
579
|
-
subtitle,
|
|
580
|
-
buttons = [],
|
|
581
|
-
onClose,
|
|
582
|
-
backButton,
|
|
583
|
-
attrs = {}
|
|
584
|
-
} = header;
|
|
585
|
-
function close(e) {
|
|
586
|
-
e.stopPropagation();
|
|
587
|
-
e.preventDefault();
|
|
588
|
-
if (typeof onClose === 'function') {
|
|
589
|
-
onClose({
|
|
590
|
-
state,
|
|
591
|
-
setState
|
|
592
|
-
});
|
|
593
|
-
} else {
|
|
594
|
-
handleClose();
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
function backButton_node() {
|
|
598
|
-
if (!backButton || onClose === false) {
|
|
599
|
-
return null;
|
|
600
|
-
}
|
|
601
|
-
let path, style;
|
|
602
|
-
if (rtl) {
|
|
603
|
-
path = mdiChevronRight;
|
|
604
|
-
style = {
|
|
605
|
-
marginLeft: 12
|
|
606
|
-
};
|
|
607
|
-
} else {
|
|
608
|
-
path = mdiChevronLeft;
|
|
609
|
-
style = {
|
|
610
|
-
marginRight: 12
|
|
611
|
-
};
|
|
612
|
-
}
|
|
613
|
-
return /*#__PURE__*/_jsx("div", {
|
|
614
|
-
style: {
|
|
615
|
-
display: 'flex',
|
|
616
|
-
alignItems: 'center',
|
|
617
|
-
justifyContent: 'center',
|
|
618
|
-
...style
|
|
619
|
-
},
|
|
620
|
-
onClick: e => close(e),
|
|
621
|
-
children: /*#__PURE__*/_jsx(Icon, {
|
|
622
|
-
path: path,
|
|
623
|
-
size: 1
|
|
624
|
-
})
|
|
625
|
-
});
|
|
626
|
-
}
|
|
627
|
-
function title_node() {
|
|
628
|
-
if (!title) {
|
|
629
|
-
return null;
|
|
630
|
-
}
|
|
631
|
-
if (!subtitle) {
|
|
632
|
-
return /*#__PURE__*/_jsx("div", {
|
|
633
|
-
className: "aio-popup-title",
|
|
634
|
-
style: {
|
|
635
|
-
display: 'flex',
|
|
636
|
-
alignItems: 'center',
|
|
637
|
-
flex: 1
|
|
638
|
-
},
|
|
639
|
-
children: title
|
|
640
|
-
});
|
|
641
|
-
} else {
|
|
642
|
-
return /*#__PURE__*/_jsxs("div", {
|
|
643
|
-
style: {
|
|
644
|
-
display: 'flex',
|
|
645
|
-
flexDirection: 'column',
|
|
646
|
-
justifyContent: 'center',
|
|
647
|
-
flex: 1
|
|
648
|
-
},
|
|
649
|
-
children: [/*#__PURE__*/_jsx("div", {
|
|
650
|
-
className: "aio-popup-title",
|
|
651
|
-
children: title
|
|
652
|
-
}), /*#__PURE__*/_jsx("div", {
|
|
653
|
-
className: "aio-popup-subtitle",
|
|
654
|
-
children: subtitle
|
|
655
|
-
})]
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
function buttons_node() {
|
|
660
|
-
if (!buttons.length) {
|
|
661
|
-
return null;
|
|
662
|
-
}
|
|
663
|
-
return /*#__PURE__*/_jsx("div", {
|
|
664
|
-
className: "aio-popup-header-buttons",
|
|
665
|
-
children: buttons.map(o => button_node(o))
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
function button_node(p) {
|
|
669
|
-
let [text, attrs = {}] = p;
|
|
670
|
-
let {
|
|
671
|
-
onClick = () => {},
|
|
672
|
-
className
|
|
673
|
-
} = attrs;
|
|
674
|
-
let Attrs = {
|
|
675
|
-
...attrs
|
|
676
|
-
};
|
|
677
|
-
Attrs.className = 'aio-popup-header-button' + (className ? ' ' + className : '');
|
|
678
|
-
Attrs.onClick = () => onClick({
|
|
679
|
-
close: handleClose,
|
|
680
|
-
state,
|
|
681
|
-
setState
|
|
682
|
-
});
|
|
683
|
-
return /*#__PURE__*/_jsx("button", {
|
|
684
|
-
...Attrs,
|
|
685
|
-
children: text
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
function close_node() {
|
|
689
|
-
if (backButton || onClose === false) {
|
|
690
|
-
return null;
|
|
691
|
-
}
|
|
692
|
-
return /*#__PURE__*/_jsx("div", {
|
|
693
|
-
className: "aio-popup-header-close-button",
|
|
694
|
-
onClick: e => close(e),
|
|
695
|
-
children: /*#__PURE__*/_jsx(Icon, {
|
|
696
|
-
path: mdiClose,
|
|
697
|
-
size: 0.8
|
|
698
|
-
})
|
|
699
|
-
});
|
|
700
|
-
}
|
|
701
|
-
let className = 'aio-popup-header' + (attrs.className ? ' ' + attrs.className : '');
|
|
702
|
-
let style = attrs.style;
|
|
703
|
-
let p = {
|
|
704
|
-
...attrs,
|
|
705
|
-
className,
|
|
706
|
-
style
|
|
707
|
-
};
|
|
708
|
-
return /*#__PURE__*/_jsxs("div", {
|
|
709
|
-
...p,
|
|
710
|
-
children: [backButton_node(), " ", title_node(), " ", buttons_node(), " ", close_node()]
|
|
711
|
-
});
|
|
712
|
-
}
|
|
713
|
-
function ModalBody(props) {
|
|
714
|
-
let {
|
|
715
|
-
handleClose,
|
|
716
|
-
body,
|
|
717
|
-
updatePopoverStyle,
|
|
718
|
-
state = {},
|
|
719
|
-
setState
|
|
720
|
-
} = props;
|
|
721
|
-
let {
|
|
722
|
-
render,
|
|
723
|
-
attrs = {}
|
|
724
|
-
} = body || {};
|
|
725
|
-
let content = typeof render === 'function' ? render({
|
|
726
|
-
close: handleClose,
|
|
727
|
-
state,
|
|
728
|
-
setState
|
|
729
|
-
}) : render;
|
|
730
|
-
useEffect(() => {
|
|
731
|
-
updatePopoverStyle();
|
|
732
|
-
}, [content]);
|
|
733
|
-
return /*#__PURE__*/_jsx("div", {
|
|
734
|
-
...attrs,
|
|
735
|
-
className: 'aio-popup-body aio-popup-scroll' + (attrs.className ? ' ' + attrs.className : ''),
|
|
736
|
-
children: typeof render === 'function' && content
|
|
737
|
-
});
|
|
738
|
-
}
|
|
739
|
-
function ModalFooter(props) {
|
|
740
|
-
let {
|
|
741
|
-
footer,
|
|
742
|
-
handleClose,
|
|
743
|
-
state,
|
|
744
|
-
setState
|
|
745
|
-
} = props;
|
|
746
|
-
if ( /*#__PURE__*/isValidElement(footer)) {
|
|
747
|
-
return footer;
|
|
748
|
-
}
|
|
749
|
-
if (typeof footer !== 'object') {
|
|
750
|
-
return null;
|
|
751
|
-
}
|
|
752
|
-
let {
|
|
753
|
-
attrs = {},
|
|
754
|
-
buttons = []
|
|
755
|
-
} = footer;
|
|
756
|
-
function buttons_node() {
|
|
757
|
-
return !buttons.length ? null : buttons.map(o => button_node(o));
|
|
758
|
-
}
|
|
759
|
-
function button_node(p) {
|
|
760
|
-
let [text, attrs = {}] = p;
|
|
761
|
-
let Attrs = typeof attrs === 'function' ? {
|
|
762
|
-
...attrs({
|
|
763
|
-
state,
|
|
764
|
-
setState
|
|
765
|
-
})
|
|
766
|
-
} : {
|
|
767
|
-
...attrs
|
|
768
|
-
};
|
|
769
|
-
let {
|
|
770
|
-
onClick = () => {},
|
|
771
|
-
className
|
|
772
|
-
} = Attrs;
|
|
773
|
-
Attrs.className = 'aio-popup-footer-button' + (className ? ' ' + className : '');
|
|
774
|
-
Attrs.onClick = () => onClick({
|
|
775
|
-
close: handleClose,
|
|
776
|
-
state,
|
|
777
|
-
setState
|
|
778
|
-
});
|
|
779
|
-
return /*#__PURE__*/_jsx("button", {
|
|
780
|
-
...Attrs,
|
|
781
|
-
children: text
|
|
782
|
-
}, text);
|
|
783
|
-
}
|
|
784
|
-
let p = {
|
|
785
|
-
className: 'aio-popup-footer' + (attrs.className ? ' ' + attrs.className : ''),
|
|
786
|
-
style: attrs.style
|
|
787
|
-
};
|
|
788
|
-
return /*#__PURE__*/_jsx("div", {
|
|
789
|
-
...p,
|
|
790
|
-
children: buttons_node()
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
function Alert(props) {
|
|
794
|
-
let {
|
|
795
|
-
icon,
|
|
796
|
-
type = '',
|
|
797
|
-
text = '',
|
|
798
|
-
subtext = '',
|
|
799
|
-
time = 10,
|
|
800
|
-
className,
|
|
801
|
-
closeText = 'بستن',
|
|
802
|
-
position = 'center'
|
|
803
|
-
} = props;
|
|
804
|
-
let $$ = {
|
|
805
|
-
id: '',
|
|
806
|
-
time: 0,
|
|
807
|
-
getId() {
|
|
808
|
-
return 'aa' + Math.round(Math.random() * 100000000);
|
|
809
|
-
},
|
|
810
|
-
getBarRender() {
|
|
811
|
-
return `<div class='aio-popup-time-bar' style="width:${$$.time}%;"></div>`;
|
|
812
|
-
},
|
|
813
|
-
updateBarRender() {
|
|
814
|
-
$(`.aio-popup-alert-container.${$$.id} .aio-popup-time`).html($$.getBarRender());
|
|
815
|
-
},
|
|
816
|
-
getRender() {
|
|
817
|
-
return `
|
|
818
|
-
<div class='aio-popup-alert-container not-mounted ${$$.id} aio-popup-alert-container-${position}'>
|
|
819
|
-
<div class='aio-popup-alert aio-popup-alert-${type}'>
|
|
820
|
-
<div class='aio-popup-alert-header'>${$$.getIcon()}</div>
|
|
1
|
+
import t,{Component as e,createRef as o,useEffect as i,useState as r,createContext as a,useContext as n,useRef as l,forwardRef as d,useImperativeHandle as s}from"react";import*as p from"react-dom/server";import{Icon as c}from"@mdi/react";import{mdiClose as u}from"@mdi/js";import _ from"jquery";import"./index.css";import{AddToAttrs as m}from"aio-utils";import{jsx as h}from"react/jsx-runtime";import{Fragment as $}from"react/jsx-runtime";import{jsxs as f}from"react/jsx-runtime";import{createElement as g}from"react";function _defineProperty(t,e,o){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}function _toPropertyKey(t){var e=_toPrimitive(t,"string");return"symbol"==typeof e?e:String(e)}function _toPrimitive(t,e){if("object"!=typeof t||null===t)return t;var o=t[Symbol.toPrimitive];if(void 0!==o){var i=o.call(t,e||"default");if("object"!=typeof i)return i;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}export default class v{constructor(t){_defineProperty(this,"rtl",void 0),_defineProperty(this,"render",void 0),_defineProperty(this,"addModal",void 0),_defineProperty(this,"addAlert",void 0),_defineProperty(this,"removeModal",void 0),_defineProperty(this,"addSnackebar",void 0),_defineProperty(this,"getModals",void 0),_defineProperty(this,"addConfirm",void 0),_defineProperty(this,"addPrompt",void 0),_defineProperty(this,"popupId",void 0),_defineProperty(this,"popupsRef",void 0);let{rtl:e=!1}=t||{};this.rtl=e,this.addSnackebar=()=>{},this.popupsRef=o(),this.getModals=()=>{let t=this.popupsRef.current;return null===t?[]:t.getModals()||[]},this.addModal=t=>{let e=this.popupsRef.current;null!==e&&e.addModal(t)},this.removeModal=t=>{let e=this.popupsRef.current;null!==e&&e.removeModal(t)},this.render=()=>{let t={rtl:e,getActions:({add:t})=>this.addSnackebar=t};return f($,{children:[h(Popups,{rtl:e,ref:this.popupsRef}),h(Snackebar,{...t})]})},this.addAlert=t=>Alert(t),this.addConfirm=t=>{let{title:e,subtitle:o,text:i,submitText:r="Yes",canselText:a="No",onSubmit:n,onCansel:l=()=>{},setAttrs:d=()=>({})}=t,s={position:"center",setAttrs(t){let e=d(t);return"modal"===t?m(e,{className:"aio-popup-confirm"}):e},header:{title:e,subtitle:o},body:()=>i,footer:()=>f($,{children:[h("button",{type:"button",onClick:()=>{l(),this.removeModal()},children:a}),h("button",{type:"button",className:"active",onClick:async()=>{if(n)!1!==await n()&&this.removeModal()},children:r})]})};this.addModal(s)},this.addPrompt=t=>{let{title:e,subtitle:o,text:i,submitText:r="تایید",canselText:a="بستن",onSubmit:n,onCansel:l=()=>{},setAttrs:d=()=>({})}=t,s={position:"center",setAttrs(t){let e=d(t);return"modal"===t?m(e,{className:"aio-popup-prompt"}):e},state:{temp:""},header:{title:e,subtitle:o},body:({state:t,setState:e})=>h("textarea",{placeholder:i,value:t.temp,onChange(t){e&&e({temp:t.target.value})}}),footer:({state:t,setState:e})=>f($,{children:[h("button",{type:"button",onClick:()=>{l(),this.removeModal()},children:a}),h("button",{type:"button",className:"active",onClick:async()=>{if(n)!1!==await n(t.temp)?this.removeModal():e({temp:""})},disabled:!t.temp,children:r})]})};this.addModal(s)}}};let Popups=d((t,e)=>{let[o,i]=r([]),a=l(o);a.current=o;let{rtl:n}=t;function d(t){void 0===t.id&&(t.id="popup"+Math.round(1e6*Math.random()));let e=t;i(o=>[...o.filter(({id:e})=>e!==t.id),e])}async function p(t="last"){if("all"===t){i([]);return}if(!a.current.length)return;"last"===t&&(t=a.current[a.current.length-1].id);let e=a.current.find(e=>e.id===t);e&&(_(`[data-id=${t}]`).addClass("not-mounted"),setTimeout(()=>{"function"==typeof e.onClose&&e.onClose(),i(e=>e.filter(e=>e.id!==t))},300))}function c(){return a.current.map((t,e)=>h(Popup,{modal:t,rtl:n,isLast:e===a.current.length-1,onClose:()=>p(t.id)},t.id))}s(e,()=>({addModal:d,removeModal:p,getModals:()=>a.current}));let u=c();return u.length?h($,{children:u}):null}),CTX=a({});function Popup(t){let{modal:e,rtl:a,onClose:n,isLast:d}=t,{setAttrs:s=()=>({}),id:p,position:c="fullscreen",body:u,getTarget:$,maxHeight:g,fixStyle:v=t=>t,fitTo:b}=e,[y]=r({dom:o(),backdropDom:o(),dui:void 0,isDown:!1}),[k,C]=r({}),[M,w]=r(e.state),L=s("modal")||{},x=s("backdrop")||{},P=l(!1);async function N(){n()}function A(t){if(!y.dui)return;let e=_(t.target);"popover"===c&&e.attr("data-id")!==y.dui&&!e.parents(`[data-id=${y.dui}]`).length&&N()}i(()=>()=>{_(window).unbind("click",A)}),i(()=>{let t="popover"===c?function t(){if(!$)return{};let o=$();if(!o||!o.length)return{};let i={dom:_(y.dom.current),target:o,fitHorizontal:e.fitHorizontal,fixStyle:v,pageSelector:e.pageSelector,limitTo:e.limitTo,fitTo:b,attrs:L,rtl:a},r={...Align(i),position:"absolute"};return g&&(r.maxHeight=g),r}():{};if(console.log("updatedStyle.top",t.top),C(t),$){y.dui="a"+Math.round(1e7*Math.random());$().attr("data-id",y.dui)}setTimeout(()=>{let t=_(y.dom.current);t.removeClass("not-mounted"),_(y.backdropDom.current).removeClass("not-mounted"),t.focus()},0),_(window).unbind("click",A),_(window).bind("click",A)},[]);function H(t){if(d)27===t.keyCode&&n()}function S(){setTimeout(()=>y.isDown=!1,0)}let D,R,T,B;return h(CTX.Provider,{value:{close:N,state:M,setState:w},children:h("div",{...(D="aio-popup-backdrop",D+=` aio-popup-position-${c}`,D+=a?" rtl":" ltr",P&&(D+=" not-mounted"),m(x,{className:D,attrs:{ref:y.backdropDom,onKeyDown:H,tabIndex:0,"data-id":p,onClick:x.onClick?x.onClick:function t(e){if(!y.isDown){e.stopPropagation();_(e.target).hasClass("aio-popup-backdrop")&&N()}}}})),children:f("div",{...(R={...k,...L.style},T="ontouchstart"in document.documentElement?"onTouchStart":"onMouseDown",{...L,ref:y.dom,"data-id":e.id,tabIndex:0,onKeyDown:H,[T]:function t(e){_(window).unbind("mouseup",S),_(window).bind("mouseup",S),y.isDown=!0},className:(B="aio-popup",B+=a?" rtl":" ltr",P&&(B+=" not-mounted"),L.className&&(B+=" "+L.className),B),style:{...R}}),children:[!!e.header&&h(ModalHeader,{modal:e}),h(ModalBody,{modal:e}),!!e.footer&&h("div",{...m(s("footer"),{className:"aio-popup-footer"}),children:e.footer({state:M,setState:w,close:N})})]})})})}let ModalHeader=t=>{let e=n(CTX),{modal:o}=t,{state:i,setState:r}=e,{setAttrs:a=()=>({})}=o,l=a("modal")||{};if("function"==typeof o.header)return o.header({close:e.close,state:i,setState:r});if("object"!=typeof o.header)return null;let d="aio-popup-header",{title:s,subtitle:p,onClose:_,before:$,after:g}=o.header;function v(t){t.stopPropagation(),t.preventDefault(),"function"==typeof _?_({state:i,setState:r}):e.close()}function b(){return p?f("div",{style:{display:"flex",flexDirection:"column",justifyContent:"center",flex:1},children:[h("div",{className:`${d}-title`,children:s}),h("div",{className:`${d}-subtitle`,children:p})]}):h("div",{className:`${d}-title`,style:{display:"flex",alignItems:"center",flex:1},children:s})}return f("div",{...m(l,{className:d}),children:[void 0!==$&&h("div",{className:`${d}-before`,onClick:t=>v(t),children:$}),!!s&&b(),void 0!==g&&h("div",{className:`${d}-after`,onClick:t=>v(t),children:g}),!1!==_&&h("div",{className:`${d}-close-button`,onClick:t=>v(t),children:h(c,{path:u,size:.8})})]})},ModalBody=t=>{let{state:e,setState:o,close:i}=n(CTX),{modal:r}=t,{body:a=()=>null,setAttrs:l=()=>({})}=r,d=l("body")||{},s=a({close:i,state:e,setState:o});return s&&null!==s?h("div",{...m(d,{className:"aio-popup-body aio-popup-scroll"}),children:s}):null};function Alert(t){let{icon:e,type:o="",text:i="",subtext:r="",time:a=10,className:n,closeText:l="بستن",position:d="center"}=t,s={id:"",time:0,getId:()=>"aa"+Math.round(1e8*Math.random()),getBarRender:()=>`<div class='aio-popup-time-bar' style="width:${s.time}%;"></div>`,updateBarRender(){_(`.aio-popup-alert-container.${s.id} .aio-popup-time`).html(s.getBarRender())},getRender:()=>`
|
|
2
|
+
<div class='aio-popup-alert-container not-mounted ${s.id} aio-popup-alert-container-${d}'>
|
|
3
|
+
<div class='aio-popup-alert aio-popup-alert-${o}'>
|
|
4
|
+
<div class='aio-popup-alert-header'>${s.getIcon()}</div>
|
|
821
5
|
<div class='aio-popup-alert-body aio-popup-scroll'>
|
|
822
|
-
<div class='aio-popup-alert-text'>${
|
|
823
|
-
<div class='aio-popup-alert-subtext'>${
|
|
6
|
+
<div class='aio-popup-alert-text'>${p.renderToStaticMarkup(i)}</div>
|
|
7
|
+
<div class='aio-popup-alert-subtext'>${r}</div>
|
|
824
8
|
</div>
|
|
825
9
|
<div class='aio-popup-alert-footer'>
|
|
826
|
-
<button class='aio-popup-alert-close ${
|
|
10
|
+
<button class='aio-popup-alert-close ${s.id}'>${l}</button>
|
|
827
11
|
</div>
|
|
828
12
|
<div class='aio-popup-time'></div>
|
|
829
13
|
</div>
|
|
830
14
|
</div>
|
|
831
|
-
|
|
832
|
-
},
|
|
833
|
-
close() {
|
|
834
|
-
$$.toggleClass(false);
|
|
835
|
-
setTimeout(() => $('.' + $$.id).remove(), 200);
|
|
836
|
-
},
|
|
837
|
-
getIcon() {
|
|
838
|
-
if (icon === false) {
|
|
839
|
-
return '';
|
|
840
|
-
}
|
|
841
|
-
return icon || {
|
|
842
|
-
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>`,
|
|
843
|
-
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>`,
|
|
844
|
-
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>`,
|
|
845
|
-
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>`
|
|
846
|
-
}[type] || '';
|
|
847
|
-
},
|
|
848
|
-
startTimer() {
|
|
849
|
-
setTimeout(() => {
|
|
850
|
-
if ($$.time >= 100) {
|
|
851
|
-
$$.time = 100;
|
|
852
|
-
$$.close();
|
|
853
|
-
return;
|
|
854
|
-
}
|
|
855
|
-
$$.time += 2;
|
|
856
|
-
$$.updateBarRender();
|
|
857
|
-
$$.startTimer();
|
|
858
|
-
}, time / 50 * 1000);
|
|
859
|
-
},
|
|
860
|
-
toggleClass(mount) {
|
|
861
|
-
let dom = $(`.${$$.id}`);
|
|
862
|
-
if (mount) {
|
|
863
|
-
setTimeout(() => dom.removeClass('not-mounted'), 0);
|
|
864
|
-
} else {
|
|
865
|
-
dom.addClass('not-mounted');
|
|
866
|
-
}
|
|
867
|
-
},
|
|
868
|
-
render() {
|
|
869
|
-
$('body').append($$.getRender());
|
|
870
|
-
$('button.' + $$.id).off('click', $$.close);
|
|
871
|
-
$('button.' + $$.id).on('click', $$.close);
|
|
872
|
-
$$.toggleClass(true);
|
|
873
|
-
}
|
|
874
|
-
};
|
|
875
|
-
$$.id = $$.getId();
|
|
876
|
-
$$.render();
|
|
877
|
-
if (time) {
|
|
878
|
-
$$.startTimer();
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
class Snackebar extends Component {
|
|
882
|
-
constructor(props) {
|
|
883
|
-
super(props);
|
|
884
|
-
this.state = {
|
|
885
|
-
items: []
|
|
886
|
-
};
|
|
887
|
-
props.getActions({
|
|
888
|
-
add: this.add.bind(this)
|
|
889
|
-
});
|
|
890
|
-
}
|
|
891
|
-
add(item) {
|
|
892
|
-
let {
|
|
893
|
-
items
|
|
894
|
-
} = this.state;
|
|
895
|
-
let newItems = [...items, {
|
|
896
|
-
...item,
|
|
897
|
-
id: 'a' + Math.round(Math.random() * 1000000000)
|
|
898
|
-
}];
|
|
899
|
-
this.setState({
|
|
900
|
-
items: newItems
|
|
901
|
-
});
|
|
902
|
-
}
|
|
903
|
-
remove(id) {
|
|
904
|
-
let {
|
|
905
|
-
items
|
|
906
|
-
} = this.state;
|
|
907
|
-
let newItems = items.filter((o, i) => o.id !== id);
|
|
908
|
-
this.setState({
|
|
909
|
-
items: newItems
|
|
910
|
-
});
|
|
911
|
-
}
|
|
912
|
-
render() {
|
|
913
|
-
let {
|
|
914
|
-
items
|
|
915
|
-
} = this.state;
|
|
916
|
-
let {
|
|
917
|
-
rtl
|
|
918
|
-
} = this.props;
|
|
919
|
-
return /*#__PURE__*/_jsx(_Fragment, {
|
|
920
|
-
children: items.map((item, i) => {
|
|
921
|
-
let p = {
|
|
922
|
-
rtl,
|
|
923
|
-
item,
|
|
924
|
-
index: i,
|
|
925
|
-
onRemove: id => this.remove(id)
|
|
926
|
-
};
|
|
927
|
-
return /*#__PURE__*/_createElement(SnackebarItem, {
|
|
928
|
-
...p,
|
|
929
|
-
key: item.id
|
|
930
|
-
});
|
|
931
|
-
})
|
|
932
|
-
});
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
function SnackebarItem(props) {
|
|
936
|
-
let {
|
|
937
|
-
item,
|
|
938
|
-
onRemove,
|
|
939
|
-
index,
|
|
940
|
-
rtl
|
|
941
|
-
} = props;
|
|
942
|
-
let {
|
|
943
|
-
time = 8,
|
|
944
|
-
id,
|
|
945
|
-
text,
|
|
946
|
-
type,
|
|
947
|
-
subtext,
|
|
948
|
-
action,
|
|
949
|
-
onClose,
|
|
950
|
-
verticalAlign = 'end',
|
|
951
|
-
horizontalAlign = 'center',
|
|
952
|
-
icon,
|
|
953
|
-
attrs = {}
|
|
954
|
-
} = item;
|
|
955
|
-
if (verticalAlign !== 'start' && verticalAlign !== 'end') {
|
|
956
|
-
verticalAlign = 'end';
|
|
957
|
-
console.error('aio-popup error => snackebar item .verticalAlign should be "start" or "end"');
|
|
958
|
-
}
|
|
959
|
-
if (horizontalAlign !== 'start' && horizontalAlign !== 'end' && horizontalAlign !== 'center') {
|
|
960
|
-
horizontalAlign = 'center';
|
|
961
|
-
console.error('aio-popup error => snackebar item .horizontalAlign should be "start" or "end" or "center"');
|
|
962
|
-
}
|
|
963
|
-
let [mounted, setMounted] = useState(false);
|
|
964
|
-
useEffect(() => {
|
|
965
|
-
setTimeout(() => setMounted(true), 0);
|
|
966
|
-
setTimeout(() => remove(), time * 1000);
|
|
967
|
-
}, []);
|
|
968
|
-
function remove() {
|
|
969
|
-
setMounted(false);
|
|
970
|
-
setTimeout(() => {
|
|
971
|
-
onRemove(id);
|
|
972
|
-
}, 200);
|
|
973
|
-
}
|
|
974
|
-
function info_svg() {
|
|
975
|
-
return /*#__PURE__*/_jsx("svg", {
|
|
976
|
-
viewBox: "0 0 24 24",
|
|
977
|
-
role: "presentation",
|
|
978
|
-
style: {
|
|
979
|
-
width: '1.2rem',
|
|
980
|
-
height: '1.2rem'
|
|
981
|
-
},
|
|
982
|
-
children: /*#__PURE__*/_jsx("path", {
|
|
983
|
-
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",
|
|
984
|
-
style: {
|
|
985
|
-
fill: 'currentcolor'
|
|
986
|
-
}
|
|
987
|
-
})
|
|
988
|
-
});
|
|
989
|
-
}
|
|
990
|
-
function success_svg() {
|
|
991
|
-
return /*#__PURE__*/_jsx("svg", {
|
|
992
|
-
viewBox: "0 0 24 24",
|
|
993
|
-
role: "presentation",
|
|
994
|
-
style: {
|
|
995
|
-
width: '1.2rem',
|
|
996
|
-
height: '1.2rem'
|
|
997
|
-
},
|
|
998
|
-
children: /*#__PURE__*/_jsx("path", {
|
|
999
|
-
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",
|
|
1000
|
-
style: {
|
|
1001
|
-
fill: 'currentcolor'
|
|
1002
|
-
}
|
|
1003
|
-
})
|
|
1004
|
-
});
|
|
1005
|
-
}
|
|
1006
|
-
function getSvg(type) {
|
|
1007
|
-
return type === 'error' || type === 'warning' || type === 'info' ? info_svg() : success_svg();
|
|
1008
|
-
}
|
|
1009
|
-
function getOffsetStyle(index) {
|
|
1010
|
-
let els = $('.aio-popup-snackebar-item-container'),
|
|
1011
|
-
sum = {
|
|
1012
|
-
start: 12,
|
|
1013
|
-
end: 12
|
|
1014
|
-
};
|
|
1015
|
-
for (let i = 0; i < index; i++) {
|
|
1016
|
-
let dom = els.eq(i);
|
|
1017
|
-
let height = dom.height() + 6;
|
|
1018
|
-
let va = dom.attr('data-vertical-align');
|
|
1019
|
-
sum[va] += height;
|
|
1020
|
-
}
|
|
1021
|
-
return {
|
|
1022
|
-
[verticalAlign === 'start' ? 'top' : 'bottom']: sum[verticalAlign]
|
|
1023
|
-
};
|
|
1024
|
-
}
|
|
1025
|
-
function text_node() {
|
|
1026
|
-
return /*#__PURE__*/_jsxs("div", {
|
|
1027
|
-
className: "aio-popup-snackebar-item-text",
|
|
1028
|
-
children: [/*#__PURE__*/_jsx("div", {
|
|
1029
|
-
className: "aio-popup-snackebar-item-uptext",
|
|
1030
|
-
children: text
|
|
1031
|
-
}), !!subtext && /*#__PURE__*/_jsx("div", {
|
|
1032
|
-
className: "aio-popup-snackebar-item-subtext",
|
|
1033
|
-
children: subtext
|
|
1034
|
-
})]
|
|
1035
|
-
});
|
|
1036
|
-
}
|
|
1037
|
-
function container_node() {
|
|
1038
|
-
let className = 'aio-popup-snackebar-item-container';
|
|
1039
|
-
className += ` aio-popup-snackebar-item-container-horizontal-align-${horizontalAlign}`;
|
|
1040
|
-
if (mounted) {
|
|
1041
|
-
className += ' mounted';
|
|
1042
|
-
}
|
|
1043
|
-
if (rtl) {
|
|
1044
|
-
className += ' rtl';
|
|
1045
|
-
}
|
|
1046
|
-
let style = getOffsetStyle(index);
|
|
1047
|
-
let p = {
|
|
1048
|
-
'data-vertical-align': verticalAlign,
|
|
1049
|
-
className,
|
|
1050
|
-
style,
|
|
1051
|
-
onClick: onClose === false ? undefined : () => remove()
|
|
1052
|
-
};
|
|
1053
|
-
return /*#__PURE__*/_jsx("div", {
|
|
1054
|
-
...p,
|
|
1055
|
-
children: item_node()
|
|
1056
|
-
});
|
|
1057
|
-
}
|
|
1058
|
-
function item_node() {
|
|
1059
|
-
let className = 'aio-popup-snackebar-item';
|
|
1060
|
-
className += ` aio-popup-snackebar-item-${type}`;
|
|
1061
|
-
if (attrs.className) {
|
|
1062
|
-
className += ` ${attrs.className}`;
|
|
1063
|
-
}
|
|
1064
|
-
let p = {
|
|
1065
|
-
...attrs,
|
|
1066
|
-
className,
|
|
1067
|
-
style: attrs.style
|
|
1068
|
-
};
|
|
1069
|
-
return /*#__PURE__*/_jsxs("div", {
|
|
1070
|
-
...p,
|
|
1071
|
-
children: [icon_node(), " ", text_node(), " ", action_node(), " ", bar_node(), " "]
|
|
1072
|
-
});
|
|
1073
|
-
}
|
|
1074
|
-
function bar_node() {
|
|
1075
|
-
return /*#__PURE__*/_jsx("div", {
|
|
1076
|
-
className: "aio-popup-snackebar-bar",
|
|
1077
|
-
style: {
|
|
1078
|
-
transition: `${time}s linear`
|
|
1079
|
-
}
|
|
1080
|
-
});
|
|
1081
|
-
}
|
|
1082
|
-
function action_node() {
|
|
1083
|
-
if (!action || !action.text) {
|
|
1084
|
-
return null;
|
|
1085
|
-
}
|
|
1086
|
-
let p = {
|
|
1087
|
-
className: 'aio-popup-snackebar-item-action',
|
|
1088
|
-
onClick: e => {
|
|
1089
|
-
e.stopPropagation();
|
|
1090
|
-
action.onClick();
|
|
1091
|
-
remove();
|
|
1092
|
-
}
|
|
1093
|
-
};
|
|
1094
|
-
return /*#__PURE__*/_jsx("button", {
|
|
1095
|
-
...p,
|
|
1096
|
-
children: action.text
|
|
1097
|
-
});
|
|
1098
|
-
}
|
|
1099
|
-
function icon_node() {
|
|
1100
|
-
return /*#__PURE__*/_jsx("div", {
|
|
1101
|
-
className: `aio-popup-snackebar-item-icon`,
|
|
1102
|
-
children: !!icon ? icon : getSvg(type)
|
|
1103
|
-
});
|
|
1104
|
-
}
|
|
1105
|
-
return container_node();
|
|
1106
|
-
}
|
|
1107
|
-
//id,onClose,backdrop,getTarget,position,fixStyle,attrs,fitHorizontal,pageSelector,rtl,body
|
|
1108
|
-
|
|
1109
|
-
function Align(p) {
|
|
1110
|
-
let {
|
|
1111
|
-
dom,
|
|
1112
|
-
target,
|
|
1113
|
-
fitHorizontal,
|
|
1114
|
-
fixStyle = o => o,
|
|
1115
|
-
attrs = {},
|
|
1116
|
-
fitTo,
|
|
1117
|
-
pageSelector,
|
|
1118
|
-
rtl,
|
|
1119
|
-
openRelatedTo
|
|
1120
|
-
} = p;
|
|
1121
|
-
let $$ = {
|
|
1122
|
-
getDomLimit(dom, type) {
|
|
1123
|
-
if (fitTo && type === 'popover') {
|
|
1124
|
-
let parent = target.parents(fitTo); //notice be jaye target dom
|
|
1125
|
-
if (parent.length) {
|
|
1126
|
-
let {
|
|
1127
|
-
left,
|
|
1128
|
-
top
|
|
1129
|
-
} = parent.offset();
|
|
1130
|
-
let width = parent.width();
|
|
1131
|
-
let height = parent.height();
|
|
1132
|
-
let right = left + width;
|
|
1133
|
-
let bottom = top + height;
|
|
1134
|
-
return {
|
|
1135
|
-
left,
|
|
1136
|
-
top,
|
|
1137
|
-
right,
|
|
1138
|
-
bottom,
|
|
1139
|
-
width,
|
|
1140
|
-
height
|
|
1141
|
-
};
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
let offset = dom.offset();
|
|
1145
|
-
let left = offset.left - window.pageXOffset;
|
|
1146
|
-
let top = offset.top - window.pageYOffset;
|
|
1147
|
-
if (pageSelector && type !== 'page') {
|
|
1148
|
-
let page = $(pageSelector);
|
|
1149
|
-
try {
|
|
1150
|
-
let {
|
|
1151
|
-
left: l,
|
|
1152
|
-
top: t
|
|
1153
|
-
} = page.offset();
|
|
1154
|
-
left -= l;
|
|
1155
|
-
top -= t;
|
|
1156
|
-
} catch {}
|
|
1157
|
-
}
|
|
1158
|
-
let width = dom.outerWidth();
|
|
1159
|
-
let height = dom.outerHeight();
|
|
1160
|
-
let right = left + width;
|
|
1161
|
-
let bottom = top + height;
|
|
1162
|
-
return {
|
|
1163
|
-
left,
|
|
1164
|
-
top,
|
|
1165
|
-
right,
|
|
1166
|
-
bottom,
|
|
1167
|
-
width,
|
|
1168
|
-
height
|
|
1169
|
-
};
|
|
1170
|
-
},
|
|
1171
|
-
getPageLimit() {
|
|
1172
|
-
let page = pageSelector ? $(pageSelector) : undefined;
|
|
1173
|
-
page = Array.isArray(page) && page.length === 0 ? undefined : page;
|
|
1174
|
-
let bodyWidth = window.innerWidth;
|
|
1175
|
-
let bodyHeight = window.innerHeight;
|
|
1176
|
-
let pageLimit = page ? $$.getDomLimit(page, 'page') : {
|
|
1177
|
-
left: 0,
|
|
1178
|
-
top: 0,
|
|
1179
|
-
right: bodyWidth,
|
|
1180
|
-
bottom: bodyHeight
|
|
1181
|
-
};
|
|
1182
|
-
if (pageLimit.left < 0) {
|
|
1183
|
-
pageLimit.left = 0;
|
|
1184
|
-
}
|
|
1185
|
-
if (pageLimit.right > bodyWidth) {
|
|
1186
|
-
pageLimit.right = bodyWidth;
|
|
1187
|
-
}
|
|
1188
|
-
if (pageLimit.top < 0) {
|
|
1189
|
-
pageLimit.top = 0;
|
|
1190
|
-
}
|
|
1191
|
-
if (pageLimit.bottom > bodyHeight) {
|
|
1192
|
-
pageLimit.bottom = bodyHeight;
|
|
1193
|
-
}
|
|
1194
|
-
return pageLimit;
|
|
1195
|
-
},
|
|
1196
|
-
getRelatedToLmit() {
|
|
1197
|
-
if (!openRelatedTo) {
|
|
1198
|
-
return;
|
|
1199
|
-
}
|
|
1200
|
-
let elem = dom.parents(openRelatedTo);
|
|
1201
|
-
if (!elem.length) {
|
|
1202
|
-
return;
|
|
1203
|
-
}
|
|
1204
|
-
let offset = elem.offset();
|
|
1205
|
-
let left = offset.left - window.pageXOffset;
|
|
1206
|
-
let top = offset.top - window.pageYOffset;
|
|
1207
|
-
let width = elem.outerWidth();
|
|
1208
|
-
let height = elem.outerHeight();
|
|
1209
|
-
let right = left + width;
|
|
1210
|
-
let bottom = top + height;
|
|
1211
|
-
return {
|
|
1212
|
-
left,
|
|
1213
|
-
top,
|
|
1214
|
-
right,
|
|
1215
|
-
bottom,
|
|
1216
|
-
width,
|
|
1217
|
-
height
|
|
1218
|
-
};
|
|
1219
|
-
},
|
|
1220
|
-
align() {
|
|
1221
|
-
let pageLimit = $$.getPageLimit();
|
|
1222
|
-
let targetLimit = $$.getDomLimit(target, 'target');
|
|
1223
|
-
let domLimit = $$.getDomLimit(dom, 'popover');
|
|
1224
|
-
let overflowY;
|
|
1225
|
-
if (!fitTo) {
|
|
1226
|
-
domLimit.top = targetLimit.bottom;
|
|
1227
|
-
domLimit.bottom = domLimit.top + domLimit.height;
|
|
1228
|
-
if (fitHorizontal) {
|
|
1229
|
-
domLimit.width = targetLimit.width;
|
|
1230
|
-
domLimit.left = targetLimit.left;
|
|
1231
|
-
domLimit.right = targetLimit.left + targetLimit.width;
|
|
1232
|
-
} else {
|
|
1233
|
-
let relatedToLimit = $$.getRelatedToLmit();
|
|
1234
|
-
let parentLimit = relatedToLimit || pageLimit;
|
|
1235
|
-
//اگر راست به چپ باید باشد
|
|
1236
|
-
if (rtl) {
|
|
1237
|
-
//راست المان را با راست هدف ست کن
|
|
1238
|
-
domLimit.right = targetLimit.right;
|
|
1239
|
-
//چپ المان را بروز رسانی کن
|
|
1240
|
-
domLimit.left = domLimit.right - domLimit.width;
|
|
1241
|
-
//اگر المان از سمت چپ از صفحه بیرون زد سمت چپ المان را با سمت چپ صفحه ست کن
|
|
1242
|
-
if (domLimit.left < parentLimit.left) {
|
|
1243
|
-
domLimit.left = parentLimit.left;
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
//اگر چپ به راست باید باشد
|
|
1247
|
-
else {
|
|
1248
|
-
//چپ المان را با چپ هدف ست کن
|
|
1249
|
-
domLimit.left = targetLimit.left;
|
|
1250
|
-
//راست المان را بروز رسانی کن
|
|
1251
|
-
domLimit.right = domLimit.left + domLimit.width;
|
|
1252
|
-
//اگر المان از سمت راست صفحه بیرون زد سمت چپ المان را با پهنای المان ست کن
|
|
1253
|
-
if (domLimit.right > parentLimit.right) {
|
|
1254
|
-
domLimit.left = parentLimit.right - domLimit.width;
|
|
1255
|
-
}
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
//اگر المان از سمت پایین صفحه بیرون زد
|
|
1259
|
-
if (domLimit.bottom > pageLimit.bottom) {
|
|
1260
|
-
if (domLimit.height > targetLimit.top - pageLimit.top) {
|
|
1261
|
-
domLimit.top = pageLimit.bottom - domLimit.height;
|
|
1262
|
-
} else {
|
|
1263
|
-
domLimit.top = targetLimit.top - domLimit.height;
|
|
1264
|
-
}
|
|
1265
|
-
} else {
|
|
1266
|
-
domLimit.top = targetLimit.bottom;
|
|
1267
|
-
}
|
|
1268
|
-
if (domLimit.height > pageLimit.bottom - pageLimit.top) {
|
|
1269
|
-
domLimit.top = 6;
|
|
1270
|
-
domLimit.bottom = undefined;
|
|
1271
|
-
domLimit.height = pageLimit.bottom - pageLimit.top - 12;
|
|
1272
|
-
overflowY = 'auto';
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
let finalStyle = {
|
|
1276
|
-
left: domLimit.left,
|
|
1277
|
-
top: domLimit.top,
|
|
1278
|
-
width: domLimit.width,
|
|
1279
|
-
height: !!fitTo ? domLimit.height : undefined,
|
|
1280
|
-
overflowY,
|
|
1281
|
-
...attrs.style
|
|
1282
|
-
};
|
|
1283
|
-
return fixStyle(finalStyle, {
|
|
1284
|
-
targetLimit,
|
|
1285
|
-
pageLimit
|
|
1286
|
-
});
|
|
1287
|
-
}
|
|
1288
|
-
};
|
|
1289
|
-
return $$.align();
|
|
1290
|
-
}
|
|
15
|
+
`,close(){s.toggleClass(!1),setTimeout(()=>_("."+s.id).remove(),200)},getIcon:()=>!1===e?"":e||({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>',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>',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>',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>'})[o]||"",startTimer(){setTimeout(()=>{if(s.time>=100){s.time=100,s.close();return}s.time+=2,s.updateBarRender(),s.startTimer()},a/50*1e3)},toggleClass(t){let e=_(`.${s.id}`);t?setTimeout(()=>e.removeClass("not-mounted"),0):e.addClass("not-mounted")},render(){_("body").append(s.getRender()),_("button."+s.id).off("click",s.close),_("button."+s.id).on("click",s.close),s.toggleClass(!0)}};s.id=s.getId(),s.render(),a&&s.startTimer()}class Snackebar extends e{constructor(t){super(t),this.state={items:[]},t.getActions({add:this.add.bind(this)})}add(t){let{items:e}=this.state,o=[...e,{...t,id:"a"+Math.round(1e9*Math.random())}];this.setState({items:o})}remove(t){let{items:e}=this.state,o=e.filter((e,o)=>e.id!==t);this.setState({items:o})}render(){let{items:t}=this.state,{rtl:e}=this.props;return h($,{children:t.map((t,o)=>g(SnackebarItem,{rtl:e,item:t,index:o,onRemove:t=>this.remove(t),key:t.id}))})}}function SnackebarItem(t){var e;let{item:o,onRemove:a,index:n,rtl:l}=t,{time:d=8,id:s,text:p,type:c,subtext:u,action:m,onClose:$,verticalAlign:g="end",horizontalAlign:v="center",icon:b,attrs:y={}}=o;"start"!==g&&"end"!==g&&(g="end",console.error('aio-popup error => snackebar item .verticalAlign should be "start" or "end"')),"start"!==v&&"end"!==v&&"center"!==v&&(v="center",console.error('aio-popup error => snackebar item .horizontalAlign should be "start" or "end" or "center"'));let[k,C]=r(!1);function M(){C(!1),setTimeout(()=>{a(s)},200)}i(()=>{setTimeout(()=>C(!0),0),setTimeout(()=>M(),1e3*d)},[]);let w,L,x,P;return w="aio-popup-snackebar-item-container",w+=` aio-popup-snackebar-item-container-horizontal-align-${v}`,k&&(w+=" mounted"),l&&(w+=" rtl"),L=function t(e){let o=_(".aio-popup-snackebar-item-container"),i={start:12,end:12};for(let r=0;r<e;r++){let a=o.eq(r),n=a.height()+6,l=a.attr("data-vertical-align");i[l]+=n}return{["start"===g?"top":"bottom"]:i[g]}}(n),x={"data-vertical-align":g,className:w,style:L,onClick:!1===$?void 0:()=>M()},h("div",{...x,children:(P="aio-popup-snackebar-item",P+=` aio-popup-snackebar-item-${c}`,y.className&&(P+=` ${y.className}`),f("div",{...{...y,className:P,style:y.style},children:[h("div",{className:"aio-popup-snackebar-item-icon",children:b||("error"===(e=c)||"warning"===e||"info"===e?h("svg",{viewBox:"0 0 24 24",role:"presentation",style:{width:"1.2rem",height:"1.2rem"},children:h("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",style:{fill:"currentcolor"}})}):h("svg",{viewBox:"0 0 24 24",role:"presentation",style:{width:"1.2rem",height:"1.2rem"},children:h("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",style:{fill:"currentcolor"}})}))})," ",f("div",{className:"aio-popup-snackebar-item-text",children:[h("div",{className:"aio-popup-snackebar-item-uptext",children:p}),!!u&&h("div",{className:"aio-popup-snackebar-item-subtext",children:u})]})," ",m&&m.text?h("button",{className:"aio-popup-snackebar-item-action",onClick(t){t.stopPropagation(),m.onClick(),M()},children:m.text}):null," ",h("div",{className:"aio-popup-snackebar-bar",style:{transition:`${d}s linear`}})," "]}))})}function Align(t){let{dom:e,target:o,fitHorizontal:i,fixStyle:r=t=>t,attrs:a={},fitTo:n,pageSelector:l,rtl:d,limitTo:s}=t,p={getDomLimit(t,e){if(n&&"popover"===e){let o=t.parents(n);if(o.length){let{left:i,top:r}=o.offset(),a=o.width(),d=o.height();return{left:i,top:r,right:i+a,bottom:r+d,width:a,height:d}}}let s=t.offset(),p=s.left-window.pageXOffset,c=s.top-window.pageYOffset;if(l&&"page"!==e){let u=_(l);try{let{left:m,top:h}=u.offset()||{left:0,top:0};p-=m,c-=h}catch{}}let $=t.outerWidth(),f=t.outerHeight(),g=p+$,v=c+f;return{left:p,top:c,right:g,bottom:v,width:$,height:f}},getPageLimit(){let t=l?_(l):void 0;t=Array.isArray(t)&&0===t.length?void 0:t;let e=window.innerWidth,o=window.innerHeight,i=t?p.getDomLimit(t,"page"):{left:0,top:0,right:e,bottom:o};return i.left<0&&(i.left=0),i.right>e&&(i.right=e),i.top<0&&(i.top=0),i.bottom>o&&(i.bottom=o),i},getRelatedToLmit(){if(!s)return;let t=e.parents(s);if(!t.length)return;let o=t.offset(),i=o.left-window.pageXOffset,r=o.top-window.pageYOffset,a=t.outerWidth(),n=t.outerHeight();return{left:i,top:r,right:i+a,bottom:r+n,width:a,height:n}},align(){let t=p.getPageLimit(),l=p.getDomLimit(o,"target"),s=p.getDomLimit(e,"popover"),c;if(!n){if(s.top=l.bottom,s.bottom=s.top+s.height,i)s.width=l.width,s.left=l.left,s.right=l.left+l.width;else{let u=p.getRelatedToLmit()||t;d?(s.right=l.right,s.left=s.right-s.width,s.left<u.left&&(s.left=u.left)):(s.left=l.left,s.right=s.left+s.width,s.right>u.right&&(s.left=u.right-s.width))}s.bottom>t.bottom?s.height>l.top-t.top?s.top=t.bottom-s.height:s.top=l.top-s.height:s.top=l.bottom,s.height>t.bottom-t.top&&(s.top=6,s.bottom=void 0,s.height=t.bottom-t.top-12,c="auto")}let _;return r({left:s.left,top:s.top,width:s.width,height:n?s.height:void 0,overflowY:c,...a.style},{targetLimit:l,pageLimit:t})}};return p.align()}
|