aio-popup 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.css +123 -30
- package/index.d.ts +166 -0
- package/index.js +1285 -11
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,16 +1,1290 @@
|
|
|
1
|
-
|
|
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:()=>`
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import React, { Component, createRef, useEffect, useState, isValidElement } from 'react';
|
|
2
|
+
import * as ReactDOMServer from 'react-dom/server';
|
|
3
|
+
import { Icon } from '@mdi/react';
|
|
4
|
+
import { mdiClose, mdiChevronRight, mdiChevronLeft } from '@mdi/js';
|
|
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>
|
|
821
|
+
<div class='aio-popup-alert-body aio-popup-scroll'>
|
|
822
|
+
<div class='aio-popup-alert-text'>${ReactDOMServer.renderToStaticMarkup(text)}</div>
|
|
823
|
+
<div class='aio-popup-alert-subtext'>${subtext}</div>
|
|
9
824
|
</div>
|
|
10
825
|
<div class='aio-popup-alert-footer'>
|
|
11
|
-
<button class='aio-popup-alert-close ${
|
|
826
|
+
<button class='aio-popup-alert-close ${$$.id}'>${closeText}</button>
|
|
12
827
|
</div>
|
|
13
828
|
<div class='aio-popup-time'></div>
|
|
14
|
-
</div>
|
|
829
|
+
</div>
|
|
15
830
|
</div>
|
|
16
|
-
|
|
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
|
+
}
|