aio-popup 1.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/README.md +1 -0
- package/index.js +1051 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# aio-popup
|
package/index.js
ADDED
|
@@ -0,0 +1,1051 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
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; }
|
|
3
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
4
|
+
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); }
|
|
5
|
+
import React, { Component, createRef, useEffect } from 'react';
|
|
6
|
+
import * as ReactDOMServer from 'react-dom/server';
|
|
7
|
+
import { Icon } from '@mdi/react';
|
|
8
|
+
import { mdiClose, mdiChevronRight, mdiChevronLeft } from '@mdi/js';
|
|
9
|
+
import RVD from 'react-virtual-dom';
|
|
10
|
+
import $ from 'jquery';
|
|
11
|
+
import './aio-popup.css';
|
|
12
|
+
export default class AIOPopup {
|
|
13
|
+
constructor(_obj = {}) {
|
|
14
|
+
_defineProperty(this, "render", () => {
|
|
15
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Popups, {
|
|
16
|
+
rtl: this.rtl,
|
|
17
|
+
getActions: ({
|
|
18
|
+
addModal,
|
|
19
|
+
removeModal,
|
|
20
|
+
getModals
|
|
21
|
+
}) => {
|
|
22
|
+
this._addModal = addModal;
|
|
23
|
+
this._removeModal = removeModal;
|
|
24
|
+
this._getModals = getModals;
|
|
25
|
+
}
|
|
26
|
+
}), /*#__PURE__*/React.createElement(AIOSnackeBar, {
|
|
27
|
+
rtl: this.rtl,
|
|
28
|
+
getActions: ({
|
|
29
|
+
add
|
|
30
|
+
}) => {
|
|
31
|
+
this._addSnakebar = add;
|
|
32
|
+
}
|
|
33
|
+
}));
|
|
34
|
+
});
|
|
35
|
+
_defineProperty(this, "getModals", () => this._getModals());
|
|
36
|
+
_defineProperty(this, "addModal", (obj = {}, animate = true) => {
|
|
37
|
+
if (obj.id === undefined) {
|
|
38
|
+
obj.id = 'popup' + Math.round(Math.random() * 1000000);
|
|
39
|
+
}
|
|
40
|
+
this._addModal(obj, animate);
|
|
41
|
+
});
|
|
42
|
+
_defineProperty(this, "removeModal", (arg, animate = true) => this._removeModal(arg, animate));
|
|
43
|
+
_defineProperty(this, "addAlert", (obj = {}) => {
|
|
44
|
+
let {
|
|
45
|
+
icon,
|
|
46
|
+
type = '',
|
|
47
|
+
text = '',
|
|
48
|
+
subtext = '',
|
|
49
|
+
time = 10,
|
|
50
|
+
className,
|
|
51
|
+
closeText = 'بستن'
|
|
52
|
+
} = obj;
|
|
53
|
+
Alert({
|
|
54
|
+
icon,
|
|
55
|
+
type,
|
|
56
|
+
text,
|
|
57
|
+
subtext,
|
|
58
|
+
time,
|
|
59
|
+
className,
|
|
60
|
+
closeText
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
_defineProperty(this, "addSnakebar", (obj = {}) => {
|
|
64
|
+
let {
|
|
65
|
+
text,
|
|
66
|
+
index,
|
|
67
|
+
type,
|
|
68
|
+
subtext,
|
|
69
|
+
action = {},
|
|
70
|
+
time = 6,
|
|
71
|
+
rtl
|
|
72
|
+
} = obj;
|
|
73
|
+
this._addSnakebar({
|
|
74
|
+
text,
|
|
75
|
+
index,
|
|
76
|
+
type,
|
|
77
|
+
subtext,
|
|
78
|
+
action,
|
|
79
|
+
time,
|
|
80
|
+
rtl
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
this.rtl = _obj.rtl;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
class Popups extends Component {
|
|
87
|
+
constructor(props) {
|
|
88
|
+
super(props);
|
|
89
|
+
this.dom = /*#__PURE__*/createRef();
|
|
90
|
+
let {
|
|
91
|
+
getActions = () => {}
|
|
92
|
+
} = props;
|
|
93
|
+
this.state = {
|
|
94
|
+
modals: []
|
|
95
|
+
};
|
|
96
|
+
getActions({
|
|
97
|
+
removeModal: this.removeModal.bind(this),
|
|
98
|
+
addModal: this.addModal.bind(this),
|
|
99
|
+
getModals: () => [...this.state.modals]
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
change(obj) {
|
|
103
|
+
let {
|
|
104
|
+
onChange = () => {}
|
|
105
|
+
} = this.props;
|
|
106
|
+
for (let prop in obj) {
|
|
107
|
+
this.state[prop] = obj[prop];
|
|
108
|
+
}
|
|
109
|
+
this.setState(obj, () => onChange({
|
|
110
|
+
...this.state
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
addModal(o, animate = true) {
|
|
114
|
+
if (typeof o !== 'object') {
|
|
115
|
+
console.error('aio-popup => addModal modal parameter to add is not an object');
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (o.id === undefined) {
|
|
119
|
+
console.error('aio-popup => addModal missing modal id property');
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
let {
|
|
123
|
+
modals
|
|
124
|
+
} = this.state;
|
|
125
|
+
let newModals = modals.filter(({
|
|
126
|
+
id
|
|
127
|
+
}) => id !== o.id);
|
|
128
|
+
newModals.push({
|
|
129
|
+
...o,
|
|
130
|
+
mounted: o.position === 'popover' ? false : !animate
|
|
131
|
+
});
|
|
132
|
+
this.change({
|
|
133
|
+
modals: newModals
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
async removeModal(arg = 'last', animate = true) {
|
|
137
|
+
if (arg === 'all') {
|
|
138
|
+
this.change({
|
|
139
|
+
modals: []
|
|
140
|
+
});
|
|
141
|
+
} else {
|
|
142
|
+
let {
|
|
143
|
+
modals
|
|
144
|
+
} = this.state;
|
|
145
|
+
if (!modals.length) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
this.mount(arg, false);
|
|
149
|
+
setTimeout(() => {
|
|
150
|
+
let modal = arg === 'last' ? modals[modals.length - 1] : modals.find(o => o.id === arg);
|
|
151
|
+
if (modal.onClose) {
|
|
152
|
+
modal.onClose();
|
|
153
|
+
}
|
|
154
|
+
if (arg === 'last') {
|
|
155
|
+
this.change({
|
|
156
|
+
modals: modals.slice(0, modals.length - 1)
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
this.change({
|
|
160
|
+
modals: modals.filter(o => o.id !== arg)
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}, animate ? 300 : 0);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
mount(id = 'last', state) {
|
|
167
|
+
try {
|
|
168
|
+
let {
|
|
169
|
+
modals
|
|
170
|
+
} = this.state;
|
|
171
|
+
if (id === 'last') {
|
|
172
|
+
id = modals[modals.length - 1].id;
|
|
173
|
+
}
|
|
174
|
+
let newModals = modals.map(o => o.id === id ? {
|
|
175
|
+
...o,
|
|
176
|
+
mounted: state
|
|
177
|
+
} : o);
|
|
178
|
+
this.change({
|
|
179
|
+
modals: newModals
|
|
180
|
+
});
|
|
181
|
+
} catch {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
getModals() {
|
|
186
|
+
let {
|
|
187
|
+
modals
|
|
188
|
+
} = this.state;
|
|
189
|
+
if (!modals.length) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
return modals.map((modal, i) => {
|
|
193
|
+
let {
|
|
194
|
+
popover,
|
|
195
|
+
position,
|
|
196
|
+
text,
|
|
197
|
+
onSubmit,
|
|
198
|
+
rtl = this.props.rtl,
|
|
199
|
+
attrs = {},
|
|
200
|
+
onClose,
|
|
201
|
+
backdrop,
|
|
202
|
+
header,
|
|
203
|
+
footer,
|
|
204
|
+
closeType,
|
|
205
|
+
body,
|
|
206
|
+
id,
|
|
207
|
+
mounted
|
|
208
|
+
} = modal;
|
|
209
|
+
let props = {
|
|
210
|
+
id,
|
|
211
|
+
backdrop,
|
|
212
|
+
footer,
|
|
213
|
+
text,
|
|
214
|
+
onSubmit,
|
|
215
|
+
header,
|
|
216
|
+
popover,
|
|
217
|
+
position,
|
|
218
|
+
rtl,
|
|
219
|
+
attrs,
|
|
220
|
+
closeType,
|
|
221
|
+
body,
|
|
222
|
+
index: i,
|
|
223
|
+
isLast: i === modals.length - 1,
|
|
224
|
+
mounted,
|
|
225
|
+
onClose: () => this.removeModal(id),
|
|
226
|
+
removeModal: this.removeModal.bind(this),
|
|
227
|
+
//use for remove lastModal by esc keyboard
|
|
228
|
+
onMount: () => this.mount(id, true)
|
|
229
|
+
};
|
|
230
|
+
return /*#__PURE__*/React.createElement(Popup, _extends({
|
|
231
|
+
key: id
|
|
232
|
+
}, props));
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
render() {
|
|
236
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, this.getModals());
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
class Popup extends Component {
|
|
240
|
+
constructor(props) {
|
|
241
|
+
super(props);
|
|
242
|
+
this.dom = /*#__PURE__*/createRef();
|
|
243
|
+
this.backdropDom = /*#__PURE__*/createRef();
|
|
244
|
+
this.state = {
|
|
245
|
+
popoverStyle: undefined
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
async onClose() {
|
|
249
|
+
let {
|
|
250
|
+
onClose
|
|
251
|
+
} = this.props;
|
|
252
|
+
onClose();
|
|
253
|
+
}
|
|
254
|
+
componentWillUnmount() {
|
|
255
|
+
$(window).unbind('click', this.handleBackClick);
|
|
256
|
+
}
|
|
257
|
+
updatePopoverStyle() {
|
|
258
|
+
let {
|
|
259
|
+
position
|
|
260
|
+
} = this.props;
|
|
261
|
+
if (position === 'popover') {
|
|
262
|
+
let popoverStyle = this.getPopoverStyle();
|
|
263
|
+
if (JSON.stringify(popoverStyle) !== JSON.stringify(this.state.popoverStyle)) {
|
|
264
|
+
this.setState({
|
|
265
|
+
popoverStyle
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
componentDidMount() {
|
|
271
|
+
let {
|
|
272
|
+
popover = {},
|
|
273
|
+
position
|
|
274
|
+
} = this.props;
|
|
275
|
+
setTimeout(() => {
|
|
276
|
+
let {
|
|
277
|
+
mounted,
|
|
278
|
+
onMount
|
|
279
|
+
} = this.props;
|
|
280
|
+
this.setState({
|
|
281
|
+
popoverStyle: position === 'popover' ? this.getPopoverStyle() : {}
|
|
282
|
+
});
|
|
283
|
+
if (!mounted) {
|
|
284
|
+
onMount();
|
|
285
|
+
}
|
|
286
|
+
}, 0);
|
|
287
|
+
if (popover.getTarget) {
|
|
288
|
+
this.dui = 'a' + Math.round(Math.random() * 10000000);
|
|
289
|
+
let target = popover.getTarget();
|
|
290
|
+
target.attr('data-uniq-id', this.dui);
|
|
291
|
+
}
|
|
292
|
+
//$(this.backdropDom.current).focus();
|
|
293
|
+
$(window).unbind('click', this.handleBackClick);
|
|
294
|
+
$(window).bind('click', $.proxy(this.handleBackClick, this));
|
|
295
|
+
}
|
|
296
|
+
handleBackClick(e) {
|
|
297
|
+
//در مود پاپاور اگر هر جایی غیر از اینپوت و پاپاور کلیک شد پاپاپ رو ببند
|
|
298
|
+
if (!this.dui) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
let {
|
|
302
|
+
position = 'fullscreen'
|
|
303
|
+
} = this.props;
|
|
304
|
+
let target = $(e.target);
|
|
305
|
+
if (position !== 'popover' || target.attr('data-uniq-id') === this.dui || target.parents(`[data-uniq-id=${this.dui}]`).length) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
this.onClose();
|
|
309
|
+
}
|
|
310
|
+
header_layout() {
|
|
311
|
+
let {
|
|
312
|
+
rtl,
|
|
313
|
+
header
|
|
314
|
+
} = this.props;
|
|
315
|
+
if (typeof header !== 'object') {
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
return {
|
|
319
|
+
html: /*#__PURE__*/React.createElement(ModalHeader, {
|
|
320
|
+
rtl: rtl,
|
|
321
|
+
header: header,
|
|
322
|
+
handleClose: () => this.onClose()
|
|
323
|
+
})
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
body_layout() {
|
|
327
|
+
let {
|
|
328
|
+
body = {}
|
|
329
|
+
} = this.props;
|
|
330
|
+
return {
|
|
331
|
+
flex: 1,
|
|
332
|
+
html: /*#__PURE__*/React.createElement(ModalBody, {
|
|
333
|
+
body: body,
|
|
334
|
+
handleClose: this.onClose.bind(this),
|
|
335
|
+
updatePopoverStyle: () => this.updatePopoverStyle()
|
|
336
|
+
})
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
footer_layout() {
|
|
340
|
+
let {
|
|
341
|
+
closeText,
|
|
342
|
+
submitText,
|
|
343
|
+
onSubmit,
|
|
344
|
+
footer,
|
|
345
|
+
type
|
|
346
|
+
} = this.props;
|
|
347
|
+
let handleClose = this.onClose.bind(this);
|
|
348
|
+
let props = {
|
|
349
|
+
closeText,
|
|
350
|
+
submitText,
|
|
351
|
+
onSubmit,
|
|
352
|
+
footer,
|
|
353
|
+
type,
|
|
354
|
+
handleClose
|
|
355
|
+
};
|
|
356
|
+
return {
|
|
357
|
+
html: /*#__PURE__*/React.createElement(ModalFooter, props)
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
getBackDropClassName() {
|
|
361
|
+
let {
|
|
362
|
+
rtl,
|
|
363
|
+
position = 'fullscreen',
|
|
364
|
+
backdrop,
|
|
365
|
+
mounted
|
|
366
|
+
} = this.props;
|
|
367
|
+
let className = 'aio-popup-backdrop';
|
|
368
|
+
if (backdrop && backdrop.attrs && backdrop.attrs.className) {
|
|
369
|
+
className += ' ' + backdrop.attrs.className;
|
|
370
|
+
}
|
|
371
|
+
className += ` aio-popup-position-${position}`;
|
|
372
|
+
className += rtl ? ' rtl' : ' ltr';
|
|
373
|
+
if (!mounted) {
|
|
374
|
+
className += ' not-mounted';
|
|
375
|
+
}
|
|
376
|
+
return className;
|
|
377
|
+
}
|
|
378
|
+
backClick(e) {
|
|
379
|
+
if (this.isDown) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
e.stopPropagation();
|
|
383
|
+
let target = $(e.target);
|
|
384
|
+
let {
|
|
385
|
+
backdrop = {}
|
|
386
|
+
} = this.props;
|
|
387
|
+
if (backdrop.close === false) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (!target.hasClass('aio-popup-backdrop')) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
this.onClose();
|
|
394
|
+
}
|
|
395
|
+
getPopoverStyle() {
|
|
396
|
+
let {
|
|
397
|
+
popover = {},
|
|
398
|
+
rtl,
|
|
399
|
+
attrs = {}
|
|
400
|
+
} = this.props;
|
|
401
|
+
let {
|
|
402
|
+
getTarget,
|
|
403
|
+
pageSelector,
|
|
404
|
+
fitHorizontal,
|
|
405
|
+
fixStyle = o => o
|
|
406
|
+
} = popover;
|
|
407
|
+
if (!getTarget) {
|
|
408
|
+
return {};
|
|
409
|
+
}
|
|
410
|
+
let target = getTarget();
|
|
411
|
+
if (!target || !target.length) {
|
|
412
|
+
return {};
|
|
413
|
+
}
|
|
414
|
+
let popup = $(this.dom.current);
|
|
415
|
+
let style = Align(popup, target, {
|
|
416
|
+
fixStyle: fixStyle,
|
|
417
|
+
pageSelector,
|
|
418
|
+
fitHorizontal,
|
|
419
|
+
style: attrs.style,
|
|
420
|
+
rtl
|
|
421
|
+
});
|
|
422
|
+
return {
|
|
423
|
+
...style,
|
|
424
|
+
position: 'absolute'
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
keyDown(e) {
|
|
428
|
+
let {
|
|
429
|
+
isLast,
|
|
430
|
+
removeModal
|
|
431
|
+
} = this.props;
|
|
432
|
+
if (!isLast) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
let code = e.keyCode;
|
|
436
|
+
if (code === 27) {
|
|
437
|
+
removeModal();
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
mouseUp() {
|
|
441
|
+
setTimeout(() => this.isDown = false, 0);
|
|
442
|
+
}
|
|
443
|
+
mouseDown(e) {
|
|
444
|
+
$(window).unbind('mouseup', this.mouseUp);
|
|
445
|
+
$(window).bind('mouseup', $.proxy(this.mouseUp, this));
|
|
446
|
+
this.isDown = true;
|
|
447
|
+
}
|
|
448
|
+
render() {
|
|
449
|
+
let {
|
|
450
|
+
rtl,
|
|
451
|
+
attrs = {},
|
|
452
|
+
backdrop = {},
|
|
453
|
+
mounted
|
|
454
|
+
} = this.props;
|
|
455
|
+
let {
|
|
456
|
+
popoverStyle
|
|
457
|
+
} = this.state;
|
|
458
|
+
let backdropAttrs = backdrop ? backdrop.attrs : {};
|
|
459
|
+
let backdropProps = {
|
|
460
|
+
...backdropAttrs,
|
|
461
|
+
className: this.getBackDropClassName(),
|
|
462
|
+
onClick: backdrop === false ? undefined : e => this.backClick(e)
|
|
463
|
+
};
|
|
464
|
+
let style = {
|
|
465
|
+
...popoverStyle,
|
|
466
|
+
...attrs.style,
|
|
467
|
+
flex: 'none'
|
|
468
|
+
};
|
|
469
|
+
let className = 'aio-popup' + (rtl ? ' rtl' : ' ltr') + (!mounted ? ' not-mounted' : '') + (attrs.className ? ' ' + attrs.className : '');
|
|
470
|
+
let ev = "ontouchstart" in document.documentElement ? 'onTouchStart' : 'onMouseDown';
|
|
471
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, backdropProps, {
|
|
472
|
+
ref: this.backdropDom,
|
|
473
|
+
onKeyDown: this.keyDown.bind(this),
|
|
474
|
+
tabIndex: 0
|
|
475
|
+
}), /*#__PURE__*/React.createElement(RVD, {
|
|
476
|
+
layout: {
|
|
477
|
+
attrs: {
|
|
478
|
+
...attrs,
|
|
479
|
+
ref: this.dom,
|
|
480
|
+
style: undefined,
|
|
481
|
+
className: undefined,
|
|
482
|
+
'data-uniq-id': this.dui,
|
|
483
|
+
[ev]: this.mouseDown.bind(this)
|
|
484
|
+
},
|
|
485
|
+
className,
|
|
486
|
+
style,
|
|
487
|
+
column: [this.header_layout(), this.body_layout(), this.footer_layout()]
|
|
488
|
+
}
|
|
489
|
+
}));
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
function ModalHeader({
|
|
493
|
+
rtl,
|
|
494
|
+
header,
|
|
495
|
+
handleClose
|
|
496
|
+
}) {
|
|
497
|
+
if (typeof header !== 'object') {
|
|
498
|
+
return null;
|
|
499
|
+
}
|
|
500
|
+
let {
|
|
501
|
+
title,
|
|
502
|
+
subtitle,
|
|
503
|
+
buttons = [],
|
|
504
|
+
onClose,
|
|
505
|
+
backButton,
|
|
506
|
+
attrs = {}
|
|
507
|
+
} = header;
|
|
508
|
+
function close(e) {
|
|
509
|
+
if (onClose) {
|
|
510
|
+
onClose(e);
|
|
511
|
+
} else {
|
|
512
|
+
handleClose();
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
function backButton_layout() {
|
|
516
|
+
if (!backButton || onClose === false) {
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
let path, style;
|
|
520
|
+
if (rtl) {
|
|
521
|
+
path = mdiChevronRight;
|
|
522
|
+
style = {
|
|
523
|
+
marginLeft: 12
|
|
524
|
+
};
|
|
525
|
+
} else {
|
|
526
|
+
path = mdiChevronLeft;
|
|
527
|
+
style = {
|
|
528
|
+
marginRight: 12
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
return {
|
|
532
|
+
html: /*#__PURE__*/React.createElement(Icon, {
|
|
533
|
+
path: path,
|
|
534
|
+
size: 1
|
|
535
|
+
}),
|
|
536
|
+
align: 'vh',
|
|
537
|
+
onClick: () => onClose(),
|
|
538
|
+
style
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
function title_layout() {
|
|
542
|
+
if (!title) {
|
|
543
|
+
return false;
|
|
544
|
+
}
|
|
545
|
+
if (!subtitle) {
|
|
546
|
+
return {
|
|
547
|
+
flex: 1,
|
|
548
|
+
align: 'v',
|
|
549
|
+
html: title,
|
|
550
|
+
className: 'aio-popup-title'
|
|
551
|
+
};
|
|
552
|
+
} else {
|
|
553
|
+
return {
|
|
554
|
+
flex: 1,
|
|
555
|
+
align: 'v',
|
|
556
|
+
column: [{
|
|
557
|
+
html: title,
|
|
558
|
+
className: 'aio-popup-title'
|
|
559
|
+
}, {
|
|
560
|
+
html: subtitle,
|
|
561
|
+
className: 'aio-popup-subtitle'
|
|
562
|
+
}]
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
function buttons_layout() {
|
|
567
|
+
if (!buttons.length) {
|
|
568
|
+
return false;
|
|
569
|
+
}
|
|
570
|
+
return {
|
|
571
|
+
gap: 6,
|
|
572
|
+
align: 'vh',
|
|
573
|
+
row: () => buttons.map(([text, attrs = {}]) => {
|
|
574
|
+
let {
|
|
575
|
+
onClick = () => {},
|
|
576
|
+
className
|
|
577
|
+
} = attrs;
|
|
578
|
+
attrs.className = 'aio-popup-header-button' + (className ? ' ' + className : '');
|
|
579
|
+
attrs.onClick = () => onClick({
|
|
580
|
+
close: handleClose
|
|
581
|
+
});
|
|
582
|
+
return {
|
|
583
|
+
html: /*#__PURE__*/React.createElement("button", attrs, text),
|
|
584
|
+
align: 'vh'
|
|
585
|
+
};
|
|
586
|
+
})
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
function close_layout() {
|
|
590
|
+
if (backButton || onClose === false) {
|
|
591
|
+
return false;
|
|
592
|
+
}
|
|
593
|
+
return {
|
|
594
|
+
html: /*#__PURE__*/React.createElement(Icon, {
|
|
595
|
+
path: mdiClose,
|
|
596
|
+
size: 0.8
|
|
597
|
+
}),
|
|
598
|
+
align: 'vh',
|
|
599
|
+
onClick: e => close(e),
|
|
600
|
+
className: 'aio-popup-header-close-button'
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
let className = 'aio-popup-header' + (attrs.className ? ' ' + attrs.className : '');
|
|
604
|
+
let style = attrs.style;
|
|
605
|
+
return /*#__PURE__*/React.createElement(RVD, {
|
|
606
|
+
layout: {
|
|
607
|
+
attrs,
|
|
608
|
+
className,
|
|
609
|
+
style,
|
|
610
|
+
row: [backButton_layout(), title_layout(), buttons_layout(), close_layout()]
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
function ModalBody(props) {
|
|
615
|
+
let {
|
|
616
|
+
handleClose,
|
|
617
|
+
body,
|
|
618
|
+
updatePopoverStyle
|
|
619
|
+
} = props;
|
|
620
|
+
let {
|
|
621
|
+
render,
|
|
622
|
+
attrs = {}
|
|
623
|
+
} = body;
|
|
624
|
+
let content = typeof render === 'function' ? render({
|
|
625
|
+
close: handleClose
|
|
626
|
+
}) : render;
|
|
627
|
+
useEffect(() => {
|
|
628
|
+
updatePopoverStyle();
|
|
629
|
+
}, [content]);
|
|
630
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, attrs, {
|
|
631
|
+
className: 'aio-popup-body' + (attrs.className ? ' ' + attrs.className : '')
|
|
632
|
+
}), typeof render === 'function' && content);
|
|
633
|
+
}
|
|
634
|
+
function ModalFooter({
|
|
635
|
+
type,
|
|
636
|
+
closeText = 'Close',
|
|
637
|
+
submitText = 'Submit',
|
|
638
|
+
footer,
|
|
639
|
+
handleClose,
|
|
640
|
+
onSubmit
|
|
641
|
+
}) {
|
|
642
|
+
if (typeof footer !== 'object') {
|
|
643
|
+
return null;
|
|
644
|
+
}
|
|
645
|
+
let {
|
|
646
|
+
attrs = {}
|
|
647
|
+
} = footer;
|
|
648
|
+
let {
|
|
649
|
+
buttons = []
|
|
650
|
+
} = footer;
|
|
651
|
+
function buttons_layout() {
|
|
652
|
+
if (!buttons.length) {
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
return {
|
|
656
|
+
gap: 6,
|
|
657
|
+
align: 'vh',
|
|
658
|
+
row: () => buttons.map(([text, attrs = {}]) => {
|
|
659
|
+
let {
|
|
660
|
+
onClick = () => {},
|
|
661
|
+
className
|
|
662
|
+
} = attrs;
|
|
663
|
+
attrs.className = 'aio-popup-footer-button' + (className ? ' ' + className : '');
|
|
664
|
+
attrs.onClick = () => onClick({
|
|
665
|
+
close: handleClose
|
|
666
|
+
});
|
|
667
|
+
return {
|
|
668
|
+
html: /*#__PURE__*/React.createElement("button", attrs, text),
|
|
669
|
+
align: 'vh'
|
|
670
|
+
};
|
|
671
|
+
})
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
let className = 'aio-popup-footer' + (attrs.className ? ' ' + attrs.className : '');
|
|
675
|
+
let style = attrs.style;
|
|
676
|
+
return /*#__PURE__*/React.createElement(RVD, {
|
|
677
|
+
layout: {
|
|
678
|
+
className,
|
|
679
|
+
style,
|
|
680
|
+
...buttons_layout()
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
function Alert(obj = {}) {
|
|
685
|
+
let {
|
|
686
|
+
icon,
|
|
687
|
+
type,
|
|
688
|
+
text,
|
|
689
|
+
subtext,
|
|
690
|
+
time,
|
|
691
|
+
className,
|
|
692
|
+
closeText
|
|
693
|
+
} = obj;
|
|
694
|
+
let $$ = {
|
|
695
|
+
time: 0,
|
|
696
|
+
getId() {
|
|
697
|
+
return 'aa' + Math.round(Math.random() * 100000000);
|
|
698
|
+
},
|
|
699
|
+
getBarRender() {
|
|
700
|
+
return `<div class='aio-popup-time-bar' style="width:${$$.time}%;"></div>`;
|
|
701
|
+
},
|
|
702
|
+
updateBarRender() {
|
|
703
|
+
$(`.aio-popup-alert-container.${$$.id} .aio-popup-time`).html($$.getBarRender());
|
|
704
|
+
},
|
|
705
|
+
getRender() {
|
|
706
|
+
return `
|
|
707
|
+
<div class='aio-popup-alert-container ${$$.id}${className ? 'aio-popup' + className : ''}'>
|
|
708
|
+
<div class='aio-popup-alert aio-popup-alert-${type}'>
|
|
709
|
+
<div class='aio-popup-alert-header'>${$$.getIcon()}</div>
|
|
710
|
+
<div class='aio-popup-alert-body'>
|
|
711
|
+
<div class='aio-popup-alert-text'>${ReactDOMServer.renderToStaticMarkup(text)}</div>
|
|
712
|
+
<div class='aio-popup-alert-subtext'>${subtext}</div>
|
|
713
|
+
</div>
|
|
714
|
+
<div class='aio-popup-alert-footer'>
|
|
715
|
+
<button class='aio-popup-alert-close ${$$.id}'>${closeText}</button>
|
|
716
|
+
</div>
|
|
717
|
+
<div class='aio-popup-time'></div>
|
|
718
|
+
</div>
|
|
719
|
+
</div>
|
|
720
|
+
`;
|
|
721
|
+
},
|
|
722
|
+
close() {
|
|
723
|
+
$('.' + $$.id).remove();
|
|
724
|
+
},
|
|
725
|
+
getIcon() {
|
|
726
|
+
if (icon === false) {
|
|
727
|
+
return '';
|
|
728
|
+
}
|
|
729
|
+
return icon || {
|
|
730
|
+
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>`,
|
|
731
|
+
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>`,
|
|
732
|
+
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>`,
|
|
733
|
+
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>`
|
|
734
|
+
}[type] || '';
|
|
735
|
+
},
|
|
736
|
+
startTimer() {
|
|
737
|
+
setTimeout(() => {
|
|
738
|
+
if ($$.time >= 100) {
|
|
739
|
+
$$.time = 100;
|
|
740
|
+
$$.close();
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
$$.time += 2;
|
|
744
|
+
$$.updateBarRender();
|
|
745
|
+
$$.startTimer();
|
|
746
|
+
}, time / 50 * 1000);
|
|
747
|
+
},
|
|
748
|
+
render() {
|
|
749
|
+
$('body').append($$.getRender());
|
|
750
|
+
$('button.' + $$.id).off('click', $$.close);
|
|
751
|
+
$('button.' + $$.id).on('click', $$.close);
|
|
752
|
+
}
|
|
753
|
+
};
|
|
754
|
+
$$.id = $$.getId();
|
|
755
|
+
$$.render();
|
|
756
|
+
if (time) {
|
|
757
|
+
$$.startTimer();
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
class AIOSnackeBar extends Component {
|
|
761
|
+
constructor(props) {
|
|
762
|
+
super(props);
|
|
763
|
+
this.state = {
|
|
764
|
+
items: []
|
|
765
|
+
};
|
|
766
|
+
props.getActions({
|
|
767
|
+
add: this.add.bind(this)
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
add(item) {
|
|
771
|
+
let {
|
|
772
|
+
items
|
|
773
|
+
} = this.state;
|
|
774
|
+
this.setState({
|
|
775
|
+
items: items.concat({
|
|
776
|
+
...item,
|
|
777
|
+
id: 'a' + Math.round(Math.random() * 1000000000)
|
|
778
|
+
})
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
remove(id) {
|
|
782
|
+
let {
|
|
783
|
+
items
|
|
784
|
+
} = this.state;
|
|
785
|
+
this.setState({
|
|
786
|
+
items: items.filter((o, i) => o.id !== id)
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
render() {
|
|
790
|
+
let {
|
|
791
|
+
items
|
|
792
|
+
} = this.state;
|
|
793
|
+
let {
|
|
794
|
+
rtl = false
|
|
795
|
+
} = this.props;
|
|
796
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, items.map((item, i) => {
|
|
797
|
+
return /*#__PURE__*/React.createElement(SnackebarItem, _extends({
|
|
798
|
+
key: item.id,
|
|
799
|
+
rtl: rtl
|
|
800
|
+
}, item, {
|
|
801
|
+
index: i,
|
|
802
|
+
onRemove: id => this.remove(id)
|
|
803
|
+
}));
|
|
804
|
+
}));
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
class SnackebarItem extends Component {
|
|
808
|
+
constructor(props) {
|
|
809
|
+
super(props);
|
|
810
|
+
this.state = {
|
|
811
|
+
mounted: false,
|
|
812
|
+
timer: 0,
|
|
813
|
+
bottom: 0
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
componentDidMount() {
|
|
817
|
+
let {
|
|
818
|
+
time = 8
|
|
819
|
+
} = this.props;
|
|
820
|
+
setTimeout(() => this.setState({
|
|
821
|
+
mounted: true
|
|
822
|
+
}), 0);
|
|
823
|
+
setTimeout(() => this.remove(), time * 1000);
|
|
824
|
+
}
|
|
825
|
+
remove() {
|
|
826
|
+
let {
|
|
827
|
+
onRemove,
|
|
828
|
+
id
|
|
829
|
+
} = this.props;
|
|
830
|
+
this.setState({
|
|
831
|
+
mounted: false
|
|
832
|
+
});
|
|
833
|
+
setTimeout(() => onRemove(id), 200);
|
|
834
|
+
}
|
|
835
|
+
info_svg() {
|
|
836
|
+
return /*#__PURE__*/React.createElement("svg", {
|
|
837
|
+
viewBox: "0 0 24 24",
|
|
838
|
+
role: "presentation",
|
|
839
|
+
style: {
|
|
840
|
+
width: '1.2rem',
|
|
841
|
+
height: '1.2rem'
|
|
842
|
+
}
|
|
843
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
844
|
+
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",
|
|
845
|
+
style: {
|
|
846
|
+
fill: 'currentcolor'
|
|
847
|
+
}
|
|
848
|
+
}));
|
|
849
|
+
}
|
|
850
|
+
success_svg() {
|
|
851
|
+
return /*#__PURE__*/React.createElement("svg", {
|
|
852
|
+
viewBox: "0 0 24 24",
|
|
853
|
+
role: "presentation",
|
|
854
|
+
style: {
|
|
855
|
+
width: '1.2rem',
|
|
856
|
+
height: '1.2rem'
|
|
857
|
+
}
|
|
858
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
859
|
+
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",
|
|
860
|
+
style: {
|
|
861
|
+
fill: 'currentcolor'
|
|
862
|
+
}
|
|
863
|
+
}));
|
|
864
|
+
}
|
|
865
|
+
getSvg(type) {
|
|
866
|
+
return type === 'error' || type === 'warning' || type === 'info' ? this.info_svg() : this.success_svg();
|
|
867
|
+
}
|
|
868
|
+
getBottom(index) {
|
|
869
|
+
let els = $('.aio-popup-snakebar-item-container'),
|
|
870
|
+
sum = 12;
|
|
871
|
+
for (let i = 0; i < index; i++) {
|
|
872
|
+
sum += els.eq(i).height() + 6;
|
|
873
|
+
}
|
|
874
|
+
return sum;
|
|
875
|
+
}
|
|
876
|
+
render() {
|
|
877
|
+
let {
|
|
878
|
+
mounted
|
|
879
|
+
} = this.state;
|
|
880
|
+
let {
|
|
881
|
+
text,
|
|
882
|
+
index,
|
|
883
|
+
type,
|
|
884
|
+
subtext,
|
|
885
|
+
action,
|
|
886
|
+
time,
|
|
887
|
+
rtl
|
|
888
|
+
} = this.props;
|
|
889
|
+
let bottom = this.getBottom(index);
|
|
890
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
891
|
+
onClick: () => this.remove(),
|
|
892
|
+
className: 'aio-popup-snakebar-item-container' + (mounted ? ' mounted' : ''),
|
|
893
|
+
style: {
|
|
894
|
+
bottom,
|
|
895
|
+
direction: rtl ? 'rtl' : undefined
|
|
896
|
+
}
|
|
897
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
898
|
+
className: `aio-popup-snakebar-item aio-popup-snakebar-item-${type}`
|
|
899
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
900
|
+
className: `aio-popup-snakebar-item-icon`
|
|
901
|
+
}, this.getSvg(type)), /*#__PURE__*/React.createElement("div", {
|
|
902
|
+
className: "aio-popup-snakebar-item-text"
|
|
903
|
+
}, /*#__PURE__*/React.createElement("div", null, text), !!subtext && /*#__PURE__*/React.createElement("div", {
|
|
904
|
+
className: "aio-popup-snakebar-item-subtext"
|
|
905
|
+
}, subtext)), !!action.text && /*#__PURE__*/React.createElement("button", {
|
|
906
|
+
className: "aio-popup-snakebar-item-action",
|
|
907
|
+
onClick: e => {
|
|
908
|
+
e.stopPropagation();
|
|
909
|
+
action.onClick();
|
|
910
|
+
this.remove();
|
|
911
|
+
}
|
|
912
|
+
}, action.text), /*#__PURE__*/React.createElement("div", {
|
|
913
|
+
className: `aio-popup-snakebar-bar`,
|
|
914
|
+
style: {
|
|
915
|
+
transition: `${time}s linear`,
|
|
916
|
+
right: rtl ? 0 : 'unset',
|
|
917
|
+
left: rtl ? 'unset' : 0
|
|
918
|
+
}
|
|
919
|
+
})));
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
//id,onClose,backdrop,getTarget,position,fixStyle,attrs,fitHorizontal,pageSelector,rtl,body
|
|
923
|
+
function Align(dom, target, config = {}) {
|
|
924
|
+
let {
|
|
925
|
+
fitHorizontal,
|
|
926
|
+
style,
|
|
927
|
+
fixStyle = o => o,
|
|
928
|
+
pageSelector,
|
|
929
|
+
rtl
|
|
930
|
+
} = config;
|
|
931
|
+
let $$ = {
|
|
932
|
+
getDomLimit(dom, type) {
|
|
933
|
+
let offset = dom.offset();
|
|
934
|
+
let left = offset.left - window.pageXOffset;
|
|
935
|
+
let top = offset.top - window.pageYOffset;
|
|
936
|
+
if (pageSelector && type !== 'page') {
|
|
937
|
+
let page = dom.parents(pageSelector);
|
|
938
|
+
try {
|
|
939
|
+
let {
|
|
940
|
+
left: l,
|
|
941
|
+
top: t
|
|
942
|
+
} = page.offset();
|
|
943
|
+
left -= l;
|
|
944
|
+
top -= t;
|
|
945
|
+
} catch {}
|
|
946
|
+
}
|
|
947
|
+
let width = dom.outerWidth();
|
|
948
|
+
let height = dom.outerHeight();
|
|
949
|
+
let right = left + width;
|
|
950
|
+
let bottom = top + height;
|
|
951
|
+
return {
|
|
952
|
+
left,
|
|
953
|
+
top,
|
|
954
|
+
right,
|
|
955
|
+
bottom,
|
|
956
|
+
width,
|
|
957
|
+
height
|
|
958
|
+
};
|
|
959
|
+
},
|
|
960
|
+
getPageLimit(dom) {
|
|
961
|
+
let page = pageSelector ? dom.parents(pageSelector) : undefined;
|
|
962
|
+
page = Array.isArray(page) && page.length === 0 ? undefined : page;
|
|
963
|
+
let bodyWidth = window.innerWidth;
|
|
964
|
+
let bodyHeight = window.innerHeight;
|
|
965
|
+
let pageLimit = page ? $$.getDomLimit(page, 'page') : {
|
|
966
|
+
left: 0,
|
|
967
|
+
top: 0,
|
|
968
|
+
right: bodyWidth,
|
|
969
|
+
bottom: bodyHeight
|
|
970
|
+
};
|
|
971
|
+
if (pageLimit.left < 0) {
|
|
972
|
+
pageLimit.left = 0;
|
|
973
|
+
}
|
|
974
|
+
if (pageLimit.right > bodyWidth) {
|
|
975
|
+
pageLimit.right = bodyWidth;
|
|
976
|
+
}
|
|
977
|
+
if (pageLimit.top < 0) {
|
|
978
|
+
pageLimit.top = 0;
|
|
979
|
+
}
|
|
980
|
+
if (pageLimit.bottom > bodyHeight) {
|
|
981
|
+
pageLimit.bottom = bodyHeight;
|
|
982
|
+
}
|
|
983
|
+
return pageLimit;
|
|
984
|
+
},
|
|
985
|
+
align() {
|
|
986
|
+
let pageLimit = $$.getPageLimit(dom);
|
|
987
|
+
let targetLimit = $$.getDomLimit(target, 'target');
|
|
988
|
+
let domLimit = $$.getDomLimit(dom, 'popover');
|
|
989
|
+
domLimit.top = targetLimit.bottom;
|
|
990
|
+
domLimit.bottom = domLimit.top + domLimit.height;
|
|
991
|
+
if (fitHorizontal) {
|
|
992
|
+
domLimit.width = targetLimit.width;
|
|
993
|
+
domLimit.left = targetLimit.left;
|
|
994
|
+
domLimit.right = targetLimit.left + targetLimit.width;
|
|
995
|
+
} else {
|
|
996
|
+
//اگر راست به چپ باید باشد
|
|
997
|
+
if (rtl) {
|
|
998
|
+
//راست المان را با راست هدف ست کن
|
|
999
|
+
domLimit.right = targetLimit.right;
|
|
1000
|
+
//چپ المان را بروز رسانی کن
|
|
1001
|
+
domLimit.left = domLimit.right - domLimit.width;
|
|
1002
|
+
//اگر المان از سمت چپ از صفحه بیرون زد سمت چپ المان را با سمت چپ صفحه ست کن
|
|
1003
|
+
if (domLimit.left < pageLimit.left) {
|
|
1004
|
+
domLimit.left = pageLimit.left;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
//اگر چپ به راست باید باشد
|
|
1008
|
+
else {
|
|
1009
|
+
//چپ المان را با چپ هدف ست کن
|
|
1010
|
+
domLimit.left = targetLimit.left;
|
|
1011
|
+
//راست المان را بروز رسانی کن
|
|
1012
|
+
domLimit.right = domLimit.left + domLimit.width;
|
|
1013
|
+
//اگر المان از سمت راست صفحه بیرون زد سمت چپ المان را با پهنای المان ست کن
|
|
1014
|
+
if (domLimit.right > pageLimit.right) {
|
|
1015
|
+
domLimit.left = pageLimit.right - domLimit.width;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
//اگر المان از سمت پایین صفحه بیرون زد
|
|
1021
|
+
if (domLimit.bottom > pageLimit.bottom) {
|
|
1022
|
+
if (domLimit.height > targetLimit.top - pageLimit.top) {
|
|
1023
|
+
domLimit.top = pageLimit.bottom - domLimit.height;
|
|
1024
|
+
} else {
|
|
1025
|
+
domLimit.top = targetLimit.top - domLimit.height;
|
|
1026
|
+
}
|
|
1027
|
+
} else {
|
|
1028
|
+
domLimit.top = targetLimit.bottom;
|
|
1029
|
+
}
|
|
1030
|
+
let overflowY;
|
|
1031
|
+
if (domLimit.height > pageLimit.bottom - pageLimit.top) {
|
|
1032
|
+
domLimit.top = 6;
|
|
1033
|
+
domLimit.bottom = undefined;
|
|
1034
|
+
domLimit.height = pageLimit.bottom - pageLimit.top - 12;
|
|
1035
|
+
overflowY = 'auto';
|
|
1036
|
+
}
|
|
1037
|
+
let finalStyle = {
|
|
1038
|
+
left: domLimit.left,
|
|
1039
|
+
top: domLimit.top,
|
|
1040
|
+
width: domLimit.width,
|
|
1041
|
+
overflowY,
|
|
1042
|
+
...style
|
|
1043
|
+
};
|
|
1044
|
+
return fixStyle(finalStyle, {
|
|
1045
|
+
targetLimit,
|
|
1046
|
+
pageLimit
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
};
|
|
1050
|
+
return $$.align();
|
|
1051
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "aio-popup",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "handle all types of popup and modals in react",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/mohammadFeiz/aio-popup.git"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@mdi/js": "^7.0.96",
|
|
15
|
+
"@mdi/react": "^1.6.1",
|
|
16
|
+
"jquery": "^3.6.1",
|
|
17
|
+
"react": "^18.2.0",
|
|
18
|
+
"react-dom": "^18.2.0",
|
|
19
|
+
"react-scripts": "5.0.1",
|
|
20
|
+
"react-virtual-dom": "^4.0.1"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"popup",
|
|
24
|
+
"modal",
|
|
25
|
+
"snakebar",
|
|
26
|
+
"alert",
|
|
27
|
+
"confirm",
|
|
28
|
+
"prompt",
|
|
29
|
+
"popover"
|
|
30
|
+
],
|
|
31
|
+
"author": "mohammad sharif feiz feiz.ms@gmail.com",
|
|
32
|
+
"license": "ISC",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/mohammadFeiz/aio-popup/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/mohammadFeiz/aio-popup#readme"
|
|
37
|
+
}
|