aio-popup 3.0.21 → 3.2.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.
Files changed (3) hide show
  1. package/index.css +217 -165
  2. package/index.js +3 -2
  3. package/package.json +1 -1
package/index.css CHANGED
@@ -1,3 +1,4 @@
1
+ /*version 3.2.0*/
1
2
  .aio-popup-backdrop {
2
3
  position: fixed;
3
4
  display: flex;
@@ -8,95 +9,114 @@
8
9
  align-items: center;
9
10
  justify-content: center;
10
11
  z-index: 10000;
11
- background:rgba(0,0,0,0.1);
12
- transition:0.3s;
12
+ background: rgba(0, 0, 0, 0.1);
13
+ transition: 0.3s;
13
14
  pointer-events: all;
14
15
  }
15
- .aio-popup.not-mounted{
16
- transition:0.3s;
16
+
17
+ .aio-popup.not-mounted {
18
+ transition: 0.3s;
17
19
  }
18
- .aio-popup-position-fullscreen > .aio-popup.not-mounted{
19
- transform:scale(0);
20
-
20
+
21
+ .aio-popup-position-fullscreen>.aio-popup.not-mounted {
22
+ transform: scale(0);
23
+
21
24
  }
22
- .aio-popup-position-popover > .aio-popup.not-mounted{
23
- opacity:0;
25
+
26
+ .aio-popup-position-popover>.aio-popup.not-mounted {
27
+ opacity: 0;
24
28
  }
25
- .aio-popup-position-top > .aio-popup.not-mounted{
26
- top:-500px;
29
+
30
+ .aio-popup-position-top>.aio-popup.not-mounted {
31
+ top: -500px;
27
32
  }
28
- .aio-popup-position-bottom > .aio-popup.not-mounted{
29
- bottom:-500px;
30
- opacity:0;
33
+
34
+ .aio-popup-position-bottom>.aio-popup.not-mounted {
35
+ bottom: -500px;
36
+ opacity: 0;
31
37
  }
32
- .aio-popup-position-right > .aio-popup.not-mounted{
33
- right:-500px;
38
+
39
+ .aio-popup-position-right>.aio-popup.not-mounted {
40
+ right: -500px;
34
41
  }
35
- .aio-popup-position-left > .aio-popup.not-mounted{
36
- left:-500px;
42
+
43
+ .aio-popup-position-left>.aio-popup.not-mounted {
44
+ left: -500px;
37
45
  }
38
- .aio-popup-position-center > .aio-popup.not-mounted{
39
- transform:translateY(500px);
40
- opacity:0;
46
+
47
+ .aio-popup-position-center>.aio-popup.not-mounted {
48
+ transform: translateY(500px);
49
+ opacity: 0;
41
50
  }
42
51
 
43
- .aio-popup-position-fullscreen > .aio-popup{
44
- width:100%;
45
- height:100%;
52
+ .aio-popup-position-fullscreen>.aio-popup {
53
+ width: 100%;
54
+ height: 100%;
46
55
  }
47
- .aio-popup-position-popover{
48
- opacity:1;
56
+
57
+ .aio-popup-position-popover {
58
+ opacity: 1;
49
59
  }
50
- .aio-popup-position-top{
60
+
61
+ .aio-popup-position-top {
51
62
  align-items: flex-start;
52
63
  }
53
- .aio-popup-position-top > .aio-popup{
54
- width:100%;
55
- max-height:90vh;
56
- top:0;
64
+
65
+ .aio-popup-position-top>.aio-popup {
66
+ width: 100%;
67
+ max-height: 90vh;
68
+ top: 0;
57
69
  }
58
- .aio-popup-position-bottom{
70
+
71
+ .aio-popup-position-bottom {
59
72
  align-items: flex-end;
60
73
  }
61
- .aio-popup-position-bottom > .aio-popup{
62
- width:100%;
63
- max-height:90vh;
64
- bottom:0;
65
- opacity:1;
74
+
75
+ .aio-popup-position-bottom>.aio-popup {
76
+ width: 100%;
77
+ max-height: 90vh;
78
+ bottom: 0;
79
+ opacity: 1;
66
80
  }
67
- .aio-popup-backdrop.not-mounted{
68
- background:none !important;
69
- transition:0.3s;
81
+
82
+ .aio-popup-backdrop.not-mounted {
83
+ background: none !important;
84
+ transition: 0.3s;
70
85
  }
71
- .aio-popup-position-right{
72
- justify-content:right;
86
+
87
+ .aio-popup-position-right {
88
+ justify-content: right;
73
89
  }
74
- .aio-popup-position-right .aio-popup{
75
- height:100%;
76
- max-width:90vh;
77
- right:0;
90
+
91
+ .aio-popup-position-right .aio-popup {
92
+ height: 100%;
93
+ max-width: 90vh;
94
+ right: 0;
78
95
  }
79
- .aio-popup-position-left{
80
- justify-content:left;
96
+
97
+ .aio-popup-position-left {
98
+ justify-content: left;
81
99
  }
82
- .aio-popup-position-left > .aio-popup{
83
- height:100%;
84
- max-width:90vh;
85
- left:0;
100
+
101
+ .aio-popup-position-left>.aio-popup {
102
+ height: 100%;
103
+ max-width: 90vh;
104
+ left: 0;
86
105
  }
87
- .aio-popup-position-center > .aio-popup{
106
+
107
+ .aio-popup-position-center>.aio-popup {
88
108
  max-width: 100vw;
89
- width:fit-content;
90
- opacity:1;
91
- max-height:100vh;
109
+ width: fit-content;
110
+ opacity: 1;
111
+ max-height: 100vh;
92
112
  }
93
113
 
94
114
  .aio-popup {
95
115
  border-radius: 4px;
96
- font-size:14px;
97
- transition:0.3s;
98
- max-width:100vw;
99
- max-height:100vh;
116
+ font-size: 14px;
117
+ transition: 0.3s;
118
+ max-width: 100vw;
119
+ max-height: 100vh;
100
120
  pointer-events: auto;
101
121
  }
102
122
 
@@ -105,42 +125,48 @@
105
125
  }
106
126
 
107
127
  .aio-popup-header {
108
- border-bottom:1px solid #e7e9ec;
109
- background:#fff;
128
+ border-bottom: 1px solid #e7e9ec;
129
+ background: #fff;
110
130
  color: #323130;
111
- padding:6px 12px;
131
+ padding: 6px 12px;
112
132
  font-size: 16px;
113
133
  font-weight: bold;
114
- min-height:48px;
134
+ min-height: 48px;
115
135
  }
116
- .aio-popup-subtitle{
117
- font-size:85%;
118
- opacity:0.5;
136
+
137
+ .aio-popup-subtitle {
138
+ font-size: 85%;
139
+ opacity: 0.5;
119
140
  }
141
+
120
142
  .aio-popup-body {
121
- background:#fff;
143
+ background: #fff;
122
144
  flex: 1;
123
145
  width: 100%;
124
- overflow-y:auto;
125
- }
126
- .aio-popup-footer{
127
- background:#fff;
128
- padding:12px;
129
- width:100%;
130
- gap:12px;
131
- display:flex;
132
- border-top:1px solid #f2f4f7;
146
+ overflow-y: auto;
147
+ }
148
+
149
+ .aio-popup-footer {
150
+ background: #fff;
151
+ padding: 12px;
152
+ width: 100%;
153
+ gap: 12px;
154
+ display: flex;
155
+ border-top: 1px solid #f2f4f7;
133
156
  justify-content: flex-end;
134
157
  }
135
- .aio-popup-header-button{
136
- padding:0 6px;
137
- background:none;
138
- border:none;
139
- cursor:pointer;
158
+
159
+ .aio-popup-header-button {
160
+ padding: 0 6px;
161
+ background: none;
162
+ border: none;
163
+ cursor: pointer;
140
164
  }
141
- .aio-popup-header-close-button{
142
- width:36px;
165
+
166
+ .aio-popup-header-close-button {
167
+ width: 36px;
143
168
  }
169
+
144
170
  .aio-popup-footer-button {
145
171
  height: 30px;
146
172
  background: dodgerblue;
@@ -150,10 +176,11 @@
150
176
  font-family: inherit;
151
177
  border-radius: 4px;
152
178
  }
153
- .aio-popup-footer-button:disabled{
154
- opacity:0.7;
155
- background:#ddd;
156
- cursor:not-allowed;
179
+
180
+ .aio-popup-footer-button:disabled {
181
+ opacity: 0.4;
182
+ background: #ddd;
183
+ cursor: not-allowed;
157
184
  }
158
185
 
159
186
  .aio-popup-blur {
@@ -185,21 +212,25 @@
185
212
  max-width: 360px;
186
213
  border-radius: 4px;
187
214
  box-shadow: 5px 8px 11px 0 rgb(0 0 0 / 17%);
188
- display:flex;
215
+ display: flex;
189
216
  flex-direction: column;
190
- overflow:hidden;
217
+ overflow: hidden;
191
218
  }
192
- .aio-popup-alert-error .aio-popup-alert-header svg{
193
- fill:red;
219
+
220
+ .aio-popup-alert-error .aio-popup-alert-header svg {
221
+ fill: red;
194
222
  }
195
- .aio-popup-alert-warning .aio-popup-alert-header svg{
196
- fill:orange;
223
+
224
+ .aio-popup-alert-warning .aio-popup-alert-header svg {
225
+ fill: orange;
197
226
  }
198
- .aio-popup-alert-info .aio-popup-alert-header svg{
199
- fill:dodgerblue;
227
+
228
+ .aio-popup-alert-info .aio-popup-alert-header svg {
229
+ fill: dodgerblue;
200
230
  }
201
- .aio-popup-alert-success .aio-popup-alert-header svg{
202
- fill:green;
231
+
232
+ .aio-popup-alert-success .aio-popup-alert-header svg {
233
+ fill: green;
203
234
  }
204
235
 
205
236
  .aio-popup-alert-header {
@@ -212,8 +243,8 @@
212
243
 
213
244
  .aio-popup-alert-body {
214
245
  padding: 0 12px;
215
- max-height:400px;
216
- overflow-y:auto;
246
+ max-height: 400px;
247
+ overflow-y: auto;
217
248
  }
218
249
 
219
250
  .aio-popup-alert-text {
@@ -243,7 +274,7 @@
243
274
  height: 3px;
244
275
  width: calc(100% - 24px);
245
276
  left: 12px;
246
- bottom:0;
277
+ bottom: 0;
247
278
  }
248
279
 
249
280
  .aio-popup-time-bar {
@@ -252,18 +283,23 @@
252
283
  height: 100%;
253
284
  left: 0;
254
285
  }
255
- .aio-popup-alert-error .aio-popup-time-bar{
256
- background:red;
286
+
287
+ .aio-popup-alert-error .aio-popup-time-bar {
288
+ background: red;
257
289
  }
258
- .aio-popup-alert-warning .aio-popup-time-bar{
259
- background:orange;
290
+
291
+ .aio-popup-alert-warning .aio-popup-time-bar {
292
+ background: orange;
260
293
  }
261
- .aio-popup-alert-info .aio-popup-time-bar{
262
- background:dodgerblue;
294
+
295
+ .aio-popup-alert-info .aio-popup-time-bar {
296
+ background: dodgerblue;
263
297
  }
264
- .aio-popup-alert-success .aio-popup-time-bar{
265
- background:green;
298
+
299
+ .aio-popup-alert-success .aio-popup-time-bar {
300
+ background: green;
266
301
  }
302
+
267
303
  .aio-popup-alert-footer button {
268
304
  border: none;
269
305
  font-family: inherit;
@@ -275,104 +311,120 @@
275
311
  border-radius: 3px;
276
312
  }
277
313
 
278
- .aio-popup-snakebar-item-container{
279
- font-size:12px;
314
+ .aio-popup-snakebar-item-container {
315
+ font-size: 12px;
280
316
  height: fit-content;
281
317
  color: #fff;
282
318
  width: 100%;
283
319
  left: 0;
284
320
  position: fixed;
285
321
  transition: 0.2s;
286
- padding:0 24px;
287
- display:flex;
322
+ padding: 0 24px;
323
+ display: flex;
288
324
  align-items: center;
289
325
  box-sizing: border-box;
290
326
  justify-content: center;
291
- z-index:1000000;
327
+ z-index: 1000000;
292
328
  }
293
- .aio-popup-snakebar-item{
329
+
330
+ .aio-popup-snakebar-item {
294
331
  background: rgb(24 28 41 / 95%);
295
- padding:12px;
296
- right:100%;
332
+ padding: 12px;
333
+ right: 100%;
297
334
  position: relative;
298
- width:100%;
335
+ width: 100%;
299
336
  height: fit-content;
300
337
  box-sizing: border-box;
301
338
  display: flex;
302
339
  align-items: center;
303
340
  transition: 0.2s;
304
- overflow:hidden;
341
+ overflow: hidden;
305
342
  }
306
- .aio-popup-snakebar-item-container.mounted .aio-popup-snakebar-item{
307
- transition:0.5s;
308
- right:0;
343
+
344
+ .aio-popup-snakebar-item-container.mounted .aio-popup-snakebar-item {
345
+ transition: 0.5s;
346
+ right: 0;
309
347
  }
310
- .aio-popup-snakebar-item-text{
311
- flex:1;
348
+
349
+ .aio-popup-snakebar-item-text {
350
+ flex: 1;
312
351
  }
313
- .aio-popup-snakebar-item-subtext{
314
- font-size:85%;
315
- opacity:0.67;
352
+
353
+ .aio-popup-snakebar-item-subtext {
354
+ font-size: 85%;
355
+ opacity: 0.67;
316
356
  }
317
- .aio-popup-snakebar-item-text svg{
318
- flex:1;
357
+
358
+ .aio-popup-snakebar-item-text svg {
359
+ flex: 1;
319
360
  }
320
- .aio-popup-snakebar-item-remove{
321
- display:flex;
322
- align-items:center;
361
+
362
+ .aio-popup-snakebar-item-remove {
363
+ display: flex;
364
+ align-items: center;
323
365
  justify-content: center;
324
366
  border-radius: 100%;
325
367
  }
326
- .aio-popup-snakebar-item-icon{
368
+
369
+ .aio-popup-snakebar-item-icon {
327
370
  display: flex;
328
371
  align-items: center;
329
372
  justify-content: center;
330
- margin-inline-end:6px;
331
- border-radius:100%;
332
- padding:3px;
373
+ margin-inline-end: 6px;
374
+ border-radius: 100%;
375
+ padding: 3px;
333
376
  }
334
- .aio-popup-snakebar-item-success .aio-popup-snakebar-item-icon{
335
- color:#5ba427;
377
+
378
+ .aio-popup-snakebar-item-success .aio-popup-snakebar-item-icon {
379
+ color: #5ba427;
336
380
  }
337
- .aio-popup-snakebar-item-error .aio-popup-snakebar-item-icon{
338
- color:#e83232;
381
+
382
+ .aio-popup-snakebar-item-error .aio-popup-snakebar-item-icon {
383
+ color: #e83232;
339
384
  }
340
- .aio-popup-snakebar-item-warning .aio-popup-snakebar-item-icon{
341
- color:#ffb300;
385
+
386
+ .aio-popup-snakebar-item-warning .aio-popup-snakebar-item-icon {
387
+ color: #ffb300;
342
388
  }
343
- .aio-popup-snakebar-item-info .aio-popup-snakebar-item-icon{
344
- color:#00bcff;
389
+
390
+ .aio-popup-snakebar-item-info .aio-popup-snakebar-item-icon {
391
+ color: #00bcff;
345
392
  }
346
393
 
347
- .aio-popup-snakebar-item-container .aio-popup-snakebar-bar{
348
- position:absolute;
349
- left:0;
350
- bottom:2px;
351
- width:0%;
352
- height:3px;
394
+ .aio-popup-snakebar-item-container .aio-popup-snakebar-bar {
395
+ position: absolute;
396
+ left: 0;
397
+ bottom: 2px;
398
+ width: 0%;
399
+ height: 3px;
353
400
  }
354
- .aio-popup-snakebar-item-container.mounted .aio-popup-snakebar-bar{
355
- width:100%;
401
+
402
+ .aio-popup-snakebar-item-container.mounted .aio-popup-snakebar-bar {
403
+ width: 100%;
356
404
  }
405
+
357
406
  /* .aio-popup-snakebar-container.mounted .aio-popup-snakebar-bar{
358
407
  width:50%;
359
408
  } */
360
409
 
361
- .aio-popup-snakebar-item-success .aio-popup-snakebar-bar{
362
- background:#5ba427;
410
+ .aio-popup-snakebar-item-success .aio-popup-snakebar-bar {
411
+ background: #5ba427;
363
412
  }
364
- .aio-popup-snakebar-item-error .aio-popup-snakebar-bar{
365
- background:#e83232;
366
- }
367
- .aio-popup-snakebar-item-warning .aio-popup-snakebar-bar{
368
- background:#ffb300;
413
+
414
+ .aio-popup-snakebar-item-error .aio-popup-snakebar-bar {
415
+ background: #e83232;
369
416
  }
370
- .aio-popup-snakebar-item-info .aio-popup-snakebar-bar{
371
- background:#00bcff;
417
+
418
+ .aio-popup-snakebar-item-warning .aio-popup-snakebar-bar {
419
+ background: #ffb300;
372
420
  }
373
- .aio-popup-snakebar-item-action{
374
- color:dodgerblue;
375
- border:none;
376
- background:none;
421
+
422
+ .aio-popup-snakebar-item-info .aio-popup-snakebar-bar {
423
+ background: #00bcff;
377
424
  }
378
425
 
426
+ .aio-popup-snakebar-item-action {
427
+ color: dodgerblue;
428
+ border: none;
429
+ background: none;
430
+ }
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
- 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)}import t,{Component as e,createRef as o,useEffect as i}from"react";import*as s from"react-dom/server";import{Icon as r}from"@mdi/react";import{mdiClose as a,mdiChevronRight as l,mdiChevronLeft as n}from"@mdi/js";import p from"react-virtual-dom";import d from"jquery";import"./index.css";import{jsx as h}from"react/jsx-runtime";import{Fragment as m}from"react/jsx-runtime";import{jsxs as u}from"react/jsx-runtime";export default class c{constructor(t={}){_defineProperty(this,"render",()=>u(m,{children:[h(Popups,{rtl:this.rtl,getActions:({addModal:t,removeModal:e,getModals:o})=>{this._addModal=t,this._removeModal=e,this._getModals=o}}),h(AIOSnackeBar,{rtl:this.rtl,getActions:({add:t})=>{this._addSnakebar=t}})]})),_defineProperty(this,"getModals",()=>this._getModals()),_defineProperty(this,"addModal",(t={},e=!0)=>{void 0===t.id&&(t.id="popup"+Math.round(1e6*Math.random())),this._addModal(t,e)}),_defineProperty(this,"addConfirm",t=>{let{title:e,subtitle:o,text:i,submitText:s="بله",canselText:r="خیر",onSubmit:a,onCansel:l=()=>{}}=t,n={position:"center",attrs:{className:"aio-popup-confirm"},header:{title:e,subtitle:o},backdrop:{attrs:{className:"rsa-backdrop"}},body:{render:()=>i},footer:{buttons:[[r,{onClick:()=>{l(),this.removeModal()}}],[s,{onClick:async()=>{!1!==await a()&&this.removeModal()},className:"active"}]]}};this.addModal(n)}),_defineProperty(this,"addPrompt",t=>{let{title:e,subtitle:o,text:i,submitText:s="تایید",canselText:r="بستن",onSubmit:a,onCansel:l=()=>{}}=t,n={position:"center",attrs:{className:"aio-popup-prompt"},state:{temp:""},header:{title:e,subtitle:o},backdrop:{attrs:{className:"rsa-backdrop"}},body:{render:({state:t,setState:e})=>h("textarea",{placeholder:i,value:t.temp,onChange:t=>e({temp:t.target.value})})},footer:{buttons:[[r,{onClick:()=>{l(),this.removeModal()}}],[s,({state:t,setState:e})=>({onClick:async({state:t})=>{!1!==await a(t.temp)?this.removeModal():e({temp:""})},disabled:!t.temp,className:"active"})]]}};this.addModal(n)}),_defineProperty(this,"removeModal",(t,e=!0)=>{this._removeModal&&this._removeModal(t,e)}),_defineProperty(this,"addAlert",(t={})=>{let{icon:e,type:o="",text:i="",subtext:s="",time:r=10,className:a,closeText:l="بستن"}=t;Alert({icon:e,type:o,text:i,subtext:s,time:r,className:a,closeText:l})}),_defineProperty(this,"addSnakebar",(t={})=>{let{text:e,index:o,type:i,subtext:s,action:r={},time:a=6,rtl:l}=t;this._addSnakebar({text:e,index:o,type:i,subtext:s,action:r,time:a,rtl:l})}),this.rtl=t.rtl}};class Popups extends e{constructor(t){super(t),this.dom=o();let{getActions:e=()=>{}}=t;this.state={modals:[]},e({removeModal:this.removeModal.bind(this),addModal:this.addModal.bind(this),getModals:()=>[...this.state.modals]})}change(t){let{onChange:e=()=>{}}=this.props;for(let o in t)this.state[o]=t[o];this.setState(t,()=>e({...this.state}))}addModal(t,e=!0){if("object"!=typeof t){console.error("aio-popup => addModal modal parameter to add is not an object");return}if(void 0===t.id){console.error("aio-popup => addModal missing modal id property");return}let{modals:o}=this.state,i=o.filter(({id:e})=>e!==t.id);i.push({...t,mounted:"popover"!==t.position&&!e}),this.change({modals:i})}async removeModal(t="last",e=!0){if("all"===t)this.change({modals:[]});else{let{modals:o}=this.state;if(!o.length)return;"last"===t&&(t=o[o.length-1].id),this.mount(t,!1),setTimeout(()=>{let{modals:e}=this.state,o=e.find(e=>e.id===t);o&&(o.onClose&&o.onClose(),this.change({modals:e.filter(e=>e.id!==t)}))},e?300:0)}}mount(t="last",e){try{let{modals:o}=this.state;"last"===t&&(t=o[o.length-1].id);let i=o.map(o=>o.id===t?{...o,mounted:e}:o);this.change({modals:i})}catch{return}}getModals(){let{modals:t}=this.state;return t.length?t.map((e,o)=>{let{popover:i,position:s,text:r,onSubmit:a,rtl:l=this.props.rtl,attrs:n={},backdrop:p,header:d,state:m,footer:u,closeType:c,body:_,id:$,mounted:g}=e;return h(Popup,{id:$,backdrop:p,footer:u,text:r,onSubmit:a,header:d,popover:i,state:m,position:s,rtl:l,attrs:n,closeType:c,body:_,index:o,isLast:o===t.length-1,mounted:g,onClose:()=>this.removeModal($),removeModal:this.removeModal.bind(this),onMount:()=>this.mount($,!0)},$)}):null}render(){return h(m,{children:this.getModals()})}}class Popup extends e{constructor(t){super(t),this.dom=o(),this.backdropDom=o(),this.state={popoverStyle:void 0,state:t.state}}async onClose(t){let{onClose:e}=this.props;e(t)}componentWillUnmount(){d(window).unbind("click",this.handleBackClick)}updatePopoverStyle(){let{position:t}=this.props;if("popover"===t){let e=this.getPopoverStyle();JSON.stringify(e)!==JSON.stringify(this.state.popoverStyle)&&this.setState({popoverStyle:e})}}componentDidMount(){let{popover:t={},position:e}=this.props;if(setTimeout(()=>{let{mounted:t,onMount:o}=this.props;this.setState({popoverStyle:"popover"===e?this.getPopoverStyle():{}}),t||o()},0),t.getTarget){this.dui="a"+Math.round(1e7*Math.random());t.getTarget().attr("data-uniq-id",this.dui)}d(window).unbind("click",this.handleBackClick),d(window).bind("click",d.proxy(this.handleBackClick,this))}handleBackClick(t){if(!this.dui)return;let{position:e="fullscreen"}=this.props,o=d(t.target);"popover"===e&&o.attr("data-uniq-id")!==this.dui&&!o.parents(`[data-uniq-id=${this.dui}]`).length&&this.onClose()}header_layout(){let{rtl:t,header:e}=this.props;if("object"!=typeof e)return!1;let{state:o}=this.state;return{html:h(ModalHeader,{rtl:t,header:e,handleClose:t=>this.onClose(t),state:o,setState:t=>this.setState({state:t})}),className:"of-visible"}}body_layout(){let{body:t={}}=this.props,{state:e}=this.state;return{flex:1,html:h(ModalBody,{body:t,state:e,setState:t=>this.setState({state:t}),handleClose:this.onClose.bind(this),updatePopoverStyle:()=>this.updatePopoverStyle()})}}footer_layout(){let{closeText:t,submitText:e,onSubmit:o,footer:i,type:s}=this.props,{state:r}=this.state,a=this.onClose.bind(this);return{html:h(ModalFooter,{closeText:t,submitText:e,onSubmit:o,footer:i,type:s,handleClose:a,state:r,setState:t=>this.setState({state:t})})}}getBackDropClassName(){let{rtl:t,position:e="fullscreen",backdrop:o,mounted:i}=this.props,s="aio-popup-backdrop";return o&&o.attrs&&o.attrs.className&&(s+=" "+o.attrs.className),s+=` aio-popup-position-${e}`,s+=t?" rtl":" ltr",i||(s+=" not-mounted"),s}backClick(t){if(this.isDown)return;t.stopPropagation();let e=d(t.target),{backdrop:o={}}=this.props;!1!==o.close&&e.hasClass("aio-popup-backdrop")&&this.onClose()}getPopoverStyle(){let{popover:t={},rtl:e,attrs:o={}}=this.props,{getTarget:i,pageSelector:s,fitHorizontal:r,fixStyle:a=t=>t}=t;if(!i)return{};let l=i();if(!l||!l.length)return{};let n=d(this.dom.current);return{...Align(n,l,{fixStyle:a,pageSelector:s,fitHorizontal:r,style:o.style,rtl:e}),position:"absolute"}}keyDown(t){let{isLast:e,removeModal:o}=this.props;if(e)27===t.keyCode&&o()}mouseUp(){setTimeout(()=>this.isDown=!1,0)}mouseDown(t){d(window).unbind("mouseup",this.mouseUp),d(window).bind("mouseup",d.proxy(this.mouseUp,this)),this.isDown=!0}render(){let{rtl:t,attrs:e={},backdrop:o={},mounted:i}=this.props,{popoverStyle:s}=this.state,r={...o?o.attrs:{},className:this.getBackDropClassName(),onClick:!1===o?void 0:t=>this.backClick(t)},a={...s,...e.style,flex:"none"},l="aio-popup"+(t?" rtl":" ltr")+(i?"":" not-mounted")+(e.className?" "+e.className:""),n="ontouchstart"in document.documentElement?"onTouchStart":"onMouseDown";return h("div",{...r,ref:this.backdropDom,onKeyDown:this.keyDown.bind(this),tabIndex:0,children:h(p,{layout:{attrs:{...e,ref:this.dom,style:void 0,className:void 0,"data-uniq-id":this.dui,[n]:this.mouseDown.bind(this)},className:l,style:a,column:[this.header_layout(),this.body_layout(),this.footer_layout()]}})})}}function ModalHeader({rtl:t,header:e,handleClose:o,state:i,setState:s}){if("object"!=typeof e)return null;let{title:d,subtitle:m,buttons:u=[],onClose:c,backButton:_,attrs:$={}}=e;function g(){c?c({state:i,setState:s}):o({state:i,setState:s})}let f="aio-popup-header"+($.className?" "+$.className:""),v=$.style;return h(p,{layout:{attrs:$,className:f,style:v,row:[function e(){if(!_||!1===c)return!1;let o,i;return t?(o=l,i={marginLeft:12}):(o=n,i={marginRight:12}),{html:h(r,{path:o,size:1}),align:"vh",onClick:()=>g(),style:i}}(),!!d&&(m?{flex:1,align:"v",column:[{html:d,className:"aio-popup-title"},{html:m,className:"aio-popup-subtitle"}]}:{flex:1,align:"v",html:d,className:"aio-popup-title"}),!!u.length&&{gap:6,align:"vh",row:()=>u.map(([t,e={}])=>{let{onClick:r=()=>{},className:a}=e,l={...e};return l.className="aio-popup-header-button"+(a?" "+a:""),l.onClick=()=>r({close:o,state:i,setState:s}),{html:h("button",{...l,children:t}),align:"vh"}})},!_&&!1!==c&&{html:h(r,{path:a,size:.8}),align:"vh",onClick:()=>g(),className:"aio-popup-header-close-button"}]}})}function ModalBody(t){let{handleClose:e,body:o,updatePopoverStyle:s,state:r,setState:a}=t,{render:l,attrs:n={}}=o,p="function"==typeof l?l({close:e,state:r,setState:a}):l;return i(()=>{s()},[p]),h("div",{...n,className:"aio-popup-body"+(n.className?" "+n.className:""),children:"function"==typeof l&&p})}function ModalFooter({footer:t,handleClose:e,state:o,setState:i}){if("object"!=typeof t)return null;let{attrs:s={},buttons:r=[]}=t,a;return h("div",{className:"aio-popup-footer"+(s.className?" "+s.className:""),style:s.style,children:r.length?r.map(([t,s={}])=>{let r="function"==typeof s?{...s({state:o,setState:i})}:{...s},{onClick:a=()=>{},className:l}=r;return r.className="aio-popup-footer-button"+(l?" "+l:""),r.onClick=()=>a({close:e,state:o,setState:i}),h("button",{...r,children:t})}):null})}function Alert(t={}){let{icon:e,type:o,text:i,subtext:r,time:a,className:l,closeText:n}=t,p={time:0,getId:()=>"aa"+Math.round(1e8*Math.random()),getBarRender:()=>`<div class='aio-popup-time-bar' style="width:${p.time}%;"></div>`,updateBarRender(){d(`.aio-popup-alert-container.${p.id} .aio-popup-time`).html(p.getBarRender())},getRender:()=>`
1
+ /**version 3.2.0 */
2
+ 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)}import t,{Component as e,createRef as o,useEffect as i}from"react";import*as s from"react-dom/server";import{Icon as r}from"@mdi/react";import{mdiClose as a,mdiChevronRight as l,mdiChevronLeft as n}from"@mdi/js";import p from"react-virtual-dom";import d from"jquery";import"./index.css";import{jsx as h}from"react/jsx-runtime";import{Fragment as m}from"react/jsx-runtime";import{jsxs as c}from"react/jsx-runtime";export default class u{constructor(t={}){_defineProperty(this,"render",()=>c(m,{children:[h(Popups,{rtl:this.rtl,getActions:({addModal:t,removeModal:e,getModals:o})=>{this._addModal=t,this._removeModal=e,this._getModals=o}}),h(AIOSnackeBar,{rtl:this.rtl,getActions:({add:t})=>{this._addSnakebar=t}})]})),_defineProperty(this,"getModals",()=>this._getModals()),_defineProperty(this,"addModal",(t={},e=!0)=>{void 0===t.id&&(t.id="popup"+Math.round(1e6*Math.random())),this._addModal(t,e)}),_defineProperty(this,"addConfirm",t=>{let{title:e,subtitle:o,text:i,submitText:s="بله",canselText:r="خیر",onSubmit:a,onCansel:l=()=>{},attrs:n={}}=t,p="aio-popup-confirm";n.className&&(p+=" "+n.className);let d={position:"center",attrs:{...n,className:p},header:{title:e,subtitle:o},backdrop:{attrs:{className:"rsa-backdrop"}},body:{render:()=>i},footer:{buttons:[[r,{onClick:()=>{l(),this.removeModal()}}],[s,{onClick:async()=>{!1!==await a()&&this.removeModal()},className:"active"}]]}};this.addModal(d)}),_defineProperty(this,"addPrompt",t=>{let{title:e,subtitle:o,text:i,submitText:s="تایید",canselText:r="بستن",onSubmit:a,onCansel:l=()=>{},attrs:n={}}=t,p="aio-popup-prompt";n.className&&(p+=" "+n.className);let d={position:"center",attrs:{...n,className:p},state:{temp:""},header:{title:e,subtitle:o},backdrop:{attrs:{className:"rsa-backdrop"}},body:{render:({state:t,setState:e})=>h("textarea",{placeholder:i,value:t.temp,onChange:t=>e({temp:t.target.value})})},footer:{buttons:[[r,{onClick:()=>{l(),this.removeModal()}}],[s,({state:t,setState:e})=>({onClick:async({state:t})=>{!1!==await a(t.temp)?this.removeModal():e({temp:""})},disabled:!t.temp,className:"active"})]]}};this.addModal(d)}),_defineProperty(this,"removeModal",(t,e=!0)=>{this._removeModal&&this._removeModal(t,e)}),_defineProperty(this,"addAlert",(t={})=>{let{icon:e,type:o="",text:i="",subtext:s="",time:r=10,className:a,closeText:l="بستن"}=t;Alert({icon:e,type:o,text:i,subtext:s,time:r,className:a,closeText:l})}),_defineProperty(this,"addSnakebar",(t={})=>{let{text:e,index:o,type:i,subtext:s,action:r={},time:a=6,rtl:l,onClose:n}=t;this._addSnakebar({text:e,index:o,type:i,subtext:s,action:r,time:a,rtl:l,onClose:n})}),this.rtl=t.rtl}};class Popups extends e{constructor(t){super(t),this.dom=o();let{getActions:e=()=>{}}=t;this.state={modals:[]},e({removeModal:this.removeModal.bind(this),addModal:this.addModal.bind(this),getModals:()=>[...this.state.modals]})}change(t){let{onChange:e=()=>{}}=this.props;for(let o in t)this.state[o]=t[o];this.setState(t,()=>e({...this.state}))}addModal(t,e=!0){if("object"!=typeof t){console.error("aio-popup => addModal modal parameter to add is not an object");return}if(void 0===t.id){console.error("aio-popup => addModal missing modal id property");return}let{modals:o}=this.state,i=o.filter(({id:e})=>e!==t.id);i.push({...t,mounted:"popover"!==t.position&&!e}),this.change({modals:i})}async removeModal(t="last",e=!0){if("all"===t)this.change({modals:[]});else{let{modals:o}=this.state;if(!o.length)return;"last"===t&&(t=o[o.length-1].id),this.mount(t,!1),setTimeout(()=>{let{modals:e}=this.state,o=e.find(e=>e.id===t);o&&(o.onClose&&o.onClose(),this.change({modals:e.filter(e=>e.id!==t)}))},e?300:0)}}mount(t="last",e){try{let{modals:o}=this.state;"last"===t&&(t=o[o.length-1].id);let i=o.map(o=>o.id===t?{...o,mounted:e}:o);this.change({modals:i})}catch{return}}getModals(){let{modals:t}=this.state;return t.length?t.map((e,o)=>{let{popover:i,position:s,text:r,onSubmit:a,rtl:l=this.props.rtl,attrs:n={},backdrop:p,header:d,state:m,footer:c,closeType:u,body:_,id:$,mounted:f}=e;return h(Popup,{id:$,backdrop:p,footer:c,text:r,onSubmit:a,header:d,popover:i,state:m,position:s,rtl:l,attrs:n,closeType:u,body:_,index:o,isLast:o===t.length-1,mounted:f,onClose:()=>this.removeModal($),removeModal:this.removeModal.bind(this),onMount:()=>this.mount($,!0)},$)}):null}render(){return h(m,{children:this.getModals()})}}class Popup extends e{constructor(t){super(t),this.dom=o(),this.backdropDom=o(),this.state={popoverStyle:void 0,state:t.state}}async onClose(t){let{onClose:e}=this.props;e(t)}componentWillUnmount(){d(window).unbind("click",this.handleBackClick)}updatePopoverStyle(){let{position:t}=this.props;if("popover"===t){let e=this.getPopoverStyle();JSON.stringify(e)!==JSON.stringify(this.state.popoverStyle)&&this.setState({popoverStyle:e})}}componentDidMount(){let{popover:t={},position:e}=this.props;if(setTimeout(()=>{let{mounted:t,onMount:o}=this.props;this.setState({popoverStyle:"popover"===e?this.getPopoverStyle():{}}),t||o()},0),t.getTarget){this.dui="a"+Math.round(1e7*Math.random());t.getTarget().attr("data-uniq-id",this.dui)}d(window).unbind("click",this.handleBackClick),d(window).bind("click",d.proxy(this.handleBackClick,this))}handleBackClick(t){if(!this.dui)return;let{position:e="fullscreen"}=this.props,o=d(t.target);"popover"===e&&o.attr("data-uniq-id")!==this.dui&&!o.parents(`[data-uniq-id=${this.dui}]`).length&&this.onClose()}header_layout(){let{rtl:t,header:e}=this.props;if("object"!=typeof e)return!1;let{state:o}=this.state;return{html:h(ModalHeader,{rtl:t,header:e,handleClose:t=>this.onClose(t),state:o,setState:t=>this.setState({state:t})}),className:"of-visible"}}body_layout(){let{body:t={}}=this.props,{state:e}=this.state;return{flex:1,html:h(ModalBody,{body:t,state:e,setState:t=>this.setState({state:t}),handleClose:this.onClose.bind(this),updatePopoverStyle:()=>this.updatePopoverStyle()})}}footer_layout(){let{closeText:t,submitText:e,onSubmit:o,footer:i,type:s}=this.props,{state:r}=this.state,a=this.onClose.bind(this);return{html:h(ModalFooter,{closeText:t,submitText:e,onSubmit:o,footer:i,type:s,handleClose:a,state:r,setState:t=>this.setState({state:t})})}}getBackDropClassName(){let{rtl:t,position:e="fullscreen",backdrop:o,mounted:i}=this.props,s="aio-popup-backdrop";return o&&o.attrs&&o.attrs.className&&(s+=" "+o.attrs.className),s+=` aio-popup-position-${e}`,s+=t?" rtl":" ltr",i||(s+=" not-mounted"),s}backClick(t){if(this.isDown)return;t.stopPropagation();let e=d(t.target),{backdrop:o={}}=this.props;!1!==o.close&&e.hasClass("aio-popup-backdrop")&&this.onClose()}getPopoverStyle(){let{popover:t={},rtl:e,attrs:o={}}=this.props,{getTarget:i,pageSelector:s,fitHorizontal:r,fixStyle:a=t=>t}=t;if(!i)return{};let l=i();if(!l||!l.length)return{};let n=d(this.dom.current);return{...Align(n,l,{fixStyle:a,pageSelector:s,fitHorizontal:r,style:o.style,rtl:e}),position:"absolute"}}keyDown(t){let{isLast:e,removeModal:o}=this.props;if(e)27===t.keyCode&&o()}mouseUp(){setTimeout(()=>this.isDown=!1,0)}mouseDown(t){d(window).unbind("mouseup",this.mouseUp),d(window).bind("mouseup",d.proxy(this.mouseUp,this)),this.isDown=!0}render(){let{rtl:t,attrs:e={},backdrop:o={},mounted:i}=this.props,{popoverStyle:s}=this.state,r={...o?o.attrs:{},className:this.getBackDropClassName(),onClick:!1===o?void 0:t=>this.backClick(t)},a={...s,...e.style,flex:"none"},l="aio-popup"+(t?" rtl":" ltr")+(i?"":" not-mounted")+(e.className?" "+e.className:""),n="ontouchstart"in document.documentElement?"onTouchStart":"onMouseDown";return h("div",{...r,ref:this.backdropDom,onKeyDown:this.keyDown.bind(this),tabIndex:0,children:h(p,{layout:{attrs:{...e,ref:this.dom,style:void 0,className:void 0,"data-uniq-id":this.dui,[n]:this.mouseDown.bind(this)},className:l,style:a,column:[this.header_layout(),this.body_layout(),this.footer_layout()]}})})}}function ModalHeader({rtl:t,header:e,handleClose:o,state:i,setState:s}){if("object"!=typeof e)return null;let{title:d,subtitle:m,buttons:c=[],onClose:u,backButton:_,attrs:$={}}=e;function f(){u?u({state:i,setState:s}):o({state:i,setState:s})}let g="aio-popup-header"+($.className?" "+$.className:""),v=$.style;return h(p,{layout:{attrs:$,className:g,style:v,row:[function e(){if(!_||!1===u)return!1;let o,i;return t?(o=l,i={marginLeft:12}):(o=n,i={marginRight:12}),{html:h(r,{path:o,size:1}),align:"vh",onClick:()=>f(),style:i}}(),!!d&&(m?{flex:1,align:"v",column:[{html:d,className:"aio-popup-title"},{html:m,className:"aio-popup-subtitle"}]}:{flex:1,align:"v",html:d,className:"aio-popup-title"}),!!c.length&&{gap:6,align:"vh",row:()=>c.map(([t,e={}])=>{let{onClick:r=()=>{},className:a}=e,l={...e};return l.className="aio-popup-header-button"+(a?" "+a:""),l.onClick=()=>r({close:o,state:i,setState:s}),{html:h("button",{...l,children:t}),align:"vh"}})},!_&&!1!==u&&{html:h(r,{path:a,size:.8}),align:"vh",onClick:()=>f(),className:"aio-popup-header-close-button"}]}})}function ModalBody(t){let{handleClose:e,body:o,updatePopoverStyle:s,state:r,setState:a}=t,{render:l,attrs:n={}}=o,p="function"==typeof l?l({close:e,state:r,setState:a}):l;return i(()=>{s()},[p]),h("div",{...n,className:"aio-popup-body"+(n.className?" "+n.className:""),children:"function"==typeof l&&p})}function ModalFooter({footer:t,handleClose:e,state:o,setState:i}){if("object"!=typeof t)return null;let{attrs:s={},buttons:r=[]}=t,a;return h("div",{className:"aio-popup-footer"+(s.className?" "+s.className:""),style:s.style,children:r.length?r.map(([t,s={}])=>{let r="function"==typeof s?{...s({state:o,setState:i})}:{...s},{onClick:a=()=>{},className:l}=r;return r.className="aio-popup-footer-button"+(l?" "+l:""),r.onClick=()=>a({close:e,state:o,setState:i}),h("button",{...r,children:t})}):null})}function Alert(t={}){let{icon:e,type:o,text:i,subtext:r,time:a,className:l,closeText:n}=t,p={time:0,getId:()=>"aa"+Math.round(1e8*Math.random()),getBarRender:()=>`<div class='aio-popup-time-bar' style="width:${p.time}%;"></div>`,updateBarRender(){d(`.aio-popup-alert-container.${p.id} .aio-popup-time`).html(p.getBarRender())},getRender:()=>`
2
3
  <div class='aio-popup-alert-container ${p.id}${l?"aio-popup"+l:""}'>
3
4
  <div class='aio-popup-alert aio-popup-alert-${o}'>
4
5
  <div class='aio-popup-alert-header'>${p.getIcon()}</div>
@@ -12,4 +13,4 @@ function _defineProperty(t,e,o){return(e=_toPropertyKey(e))in t?Object.definePro
12
13
  <div class='aio-popup-time'></div>
13
14
  </div>
14
15
  </div>
15
- `,close(){d("."+p.id).remove()},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(p.time>=100){p.time=100,p.close();return}p.time+=2,p.updateBarRender(),p.startTimer()},a/50*1e3)},render(){d("body").append(p.getRender()),d("button."+p.id).off("click",p.close),d("button."+p.id).on("click",p.close)}};p.id=p.getId(),p.render(),a&&p.startTimer()}class AIOSnackeBar extends e{constructor(t){super(t),this.state={items:[]},t.getActions({add:this.add.bind(this)})}add(t){let{items:e}=this.state;this.setState({items:e.concat({...t,id:"a"+Math.round(1e9*Math.random())})})}remove(t){let{items:e}=this.state;this.setState({items:e.filter((e,o)=>e.id!==t)})}render(){let{items:t}=this.state,{rtl:e=!1}=this.props;return h(m,{children:t.map((t,o)=>h(SnackebarItem,{rtl:e,...t,index:o,onRemove:t=>this.remove(t)},t.id))})}}class SnackebarItem extends e{constructor(t){super(t),this.state={mounted:!1,timer:0,bottom:0}}componentDidMount(){let{time:t=8}=this.props;setTimeout(()=>this.setState({mounted:!0}),0),setTimeout(()=>this.remove(),1e3*t)}remove(){let{onRemove:t,id:e}=this.props;this.setState({mounted:!1}),setTimeout(()=>t(e),200)}info_svg(){return 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"}})})}success_svg(){return 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"}})})}getSvg(t){return"error"===t||"warning"===t||"info"===t?this.info_svg():this.success_svg()}getBottom(t){let e=d(".aio-popup-snakebar-item-container"),o=12;for(let i=0;i<t;i++)o+=e.eq(i).height()+6;return o}render(){let{mounted:t}=this.state,{text:e,index:o,type:i,subtext:s,action:r,time:a,rtl:l}=this.props,n=this.getBottom(o);return h("div",{onClick:()=>this.remove(),className:"aio-popup-snakebar-item-container"+(t?" mounted":""),style:{bottom:n,direction:l?"rtl":void 0},children:u("div",{className:`aio-popup-snakebar-item aio-popup-snakebar-item-${i}`,children:[h("div",{className:"aio-popup-snakebar-item-icon",children:this.getSvg(i)}),u("div",{className:"aio-popup-snakebar-item-text",children:[h("div",{children:e}),!!s&&h("div",{className:"aio-popup-snakebar-item-subtext",children:s})]}),!!r.text&&h("button",{className:"aio-popup-snakebar-item-action",onClick:t=>{t.stopPropagation(),r.onClick(),this.remove()},children:r.text}),h("div",{className:"aio-popup-snakebar-bar",style:{transition:`${a}s linear`,right:l?0:"unset",left:l?"unset":0}})]})})}}function Align(t,e,o={}){let{fitHorizontal:i,style:s,fixStyle:r=t=>t,pageSelector:a,rtl:l}=o,n={getDomLimit(t,e){let o=t.offset(),i=o.left-window.pageXOffset,s=o.top-window.pageYOffset;if(a&&"page"!==e){let r=d(a);try{let{left:l,top:n}=r.offset();i-=l,s-=n}catch{}}let p=t.outerWidth(),h=t.outerHeight(),m=i+p,u=s+h;return{left:i,top:s,right:m,bottom:u,width:p,height:h}},getPageLimit(t){let e=a?d(a):void 0;e=Array.isArray(e)&&0===e.length?void 0:e;let o=window.innerWidth,i=window.innerHeight,s=e?n.getDomLimit(e,"page"):{left:0,top:0,right:o,bottom:i};return s.left<0&&(s.left=0),s.right>o&&(s.right=o),s.top<0&&(s.top=0),s.bottom>i&&(s.bottom=i),s},align(){let o=n.getPageLimit(t),a=n.getDomLimit(e,"target"),p=n.getDomLimit(t,"popover");p.top=a.bottom,p.bottom=p.top+p.height,i?(p.width=a.width,p.left=a.left,p.right=a.left+a.width):l?(p.right=a.right,p.left=p.right-p.width,p.left<o.left&&(p.left=o.left)):(p.left=a.left,p.right=p.left+p.width,p.right>o.right&&(p.left=o.right-p.width)),p.bottom>o.bottom?p.height>a.top-o.top?p.top=o.bottom-p.height:p.top=a.top-p.height:p.top=a.bottom;let d;p.height>o.bottom-o.top&&(p.top=6,p.bottom=void 0,p.height=o.bottom-o.top-12,d="auto");let h={left:p.left,top:p.top,width:p.width,overflowY:d,...s};return r(h,{targetLimit:a,pageLimit:o})}};return n.align()}
16
+ `,close(){d("."+p.id).remove()},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(p.time>=100){p.time=100,p.close();return}p.time+=2,p.updateBarRender(),p.startTimer()},a/50*1e3)},render(){d("body").append(p.getRender()),d("button."+p.id).off("click",p.close),d("button."+p.id).on("click",p.close)}};p.id=p.getId(),p.render(),a&&p.startTimer()}class AIOSnackeBar extends e{constructor(t){super(t),this.state={items:[]},t.getActions({add:this.add.bind(this)})}add(t){let{items:e}=this.state;this.setState({items:e.concat({...t,id:"a"+Math.round(1e9*Math.random())})})}remove(t){let{items:e}=this.state;this.setState({items:e.filter((e,o)=>e.id!==t)})}render(){let{items:t}=this.state,{rtl:e=!1}=this.props;return h(m,{children:t.map((t,o)=>h(SnackebarItem,{rtl:e,...t,index:o,onRemove:t=>this.remove(t)},t.id))})}}class SnackebarItem extends e{constructor(t){super(t),this.state={mounted:!1,timer:0,bottom:0}}componentDidMount(){let{time:t=8}=this.props;setTimeout(()=>this.setState({mounted:!0}),0),setTimeout(()=>this.remove(),1e3*t)}remove(t){let{onRemove:e,id:o}=this.props;this.setState({mounted:!1}),setTimeout(()=>{e(o),"function"==typeof t&&t()},200)}info_svg(){return 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"}})})}success_svg(){return 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"}})})}getSvg(t){return"error"===t||"warning"===t||"info"===t?this.info_svg():this.success_svg()}getBottom(t){let e=d(".aio-popup-snakebar-item-container"),o=12;for(let i=0;i<t;i++)o+=e.eq(i).height()+6;return o}render(){let{mounted:t}=this.state,{text:e,index:o,type:i,subtext:s,action:r,time:a,rtl:l,onClose:n}=this.props,p=this.getBottom(o);return h("div",{onClick:!1===n?void 0:()=>this.remove(n),className:"aio-popup-snakebar-item-container"+(t?" mounted":""),style:{bottom:p,direction:l?"rtl":void 0},children:c("div",{className:`aio-popup-snakebar-item aio-popup-snakebar-item-${i}`,children:[h("div",{className:"aio-popup-snakebar-item-icon",children:this.getSvg(i)}),c("div",{className:"aio-popup-snakebar-item-text",children:[h("div",{style:{textAlign:l?"right":"left"},children:e}),!!s&&h("div",{className:"aio-popup-snakebar-item-subtext",children:s})]}),!!r.text&&h("button",{className:"aio-popup-snakebar-item-action",onClick:t=>{t.stopPropagation(),r.onClick(),this.remove()},children:r.text}),h("div",{className:"aio-popup-snakebar-bar",style:{transition:`${a}s linear`,right:l?0:"unset",left:l?"unset":0}})]})})}}function Align(t,e,o={}){let{fitHorizontal:i,style:s,fixStyle:r=t=>t,pageSelector:a,rtl:l}=o,n={getDomLimit(t,e){let o=t.offset(),i=o.left-window.pageXOffset,s=o.top-window.pageYOffset;if(a&&"page"!==e){let r=d(a);try{let{left:l,top:n}=r.offset();i-=l,s-=n}catch{}}let p=t.outerWidth(),h=t.outerHeight(),m=i+p,c=s+h;return{left:i,top:s,right:m,bottom:c,width:p,height:h}},getPageLimit(t){let e=a?d(a):void 0;e=Array.isArray(e)&&0===e.length?void 0:e;let o=window.innerWidth,i=window.innerHeight,s=e?n.getDomLimit(e,"page"):{left:0,top:0,right:o,bottom:i};return s.left<0&&(s.left=0),s.right>o&&(s.right=o),s.top<0&&(s.top=0),s.bottom>i&&(s.bottom=i),s},align(){let o=n.getPageLimit(t),a=n.getDomLimit(e,"target"),p=n.getDomLimit(t,"popover");p.top=a.bottom,p.bottom=p.top+p.height,i?(p.width=a.width,p.left=a.left,p.right=a.left+a.width):l?(p.right=a.right,p.left=p.right-p.width,p.left<o.left&&(p.left=o.left)):(p.left=a.left,p.right=p.left+p.width,p.right>o.right&&(p.left=o.right-p.width)),p.bottom>o.bottom?p.height>a.top-o.top?p.top=o.bottom-p.height:p.top=a.top-p.height:p.top=a.bottom;let d;p.height>o.bottom-o.top&&(p.top=6,p.bottom=void 0,p.height=o.bottom-o.top-12,d="auto");let h={left:p.left,top:p.top,width:p.width,overflowY:d,...s};return r(h,{targetLimit:a,pageLimit:o})}};return n.align()}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-popup",
3
- "version": "3.0.21",
3
+ "version": "3.2.0",
4
4
  "description": "handle all types of popup and modals in react",
5
5
  "main": "index.js",
6
6
  "scripts": {