aio-popup 3.0.3 → 3.0.4
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 +5 -1
- package/index.js +1 -1
- package/package.json +1 -1
package/index.css
CHANGED
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
.aio-popup-position-right{
|
|
72
72
|
justify-content:right;
|
|
73
73
|
}
|
|
74
|
-
.aio-popup-position-right
|
|
74
|
+
.aio-popup-position-right .aio-popup{
|
|
75
75
|
height:100%;
|
|
76
76
|
max-width:90vh;
|
|
77
77
|
right:0;
|
|
@@ -120,10 +120,14 @@
|
|
|
120
120
|
.aio-popup-body {
|
|
121
121
|
flex: 1;
|
|
122
122
|
width: 100%;
|
|
123
|
+
padding:12px;
|
|
123
124
|
overflow-y:auto;
|
|
124
125
|
}
|
|
125
126
|
.aio-popup-footer{
|
|
126
127
|
padding:12px;
|
|
128
|
+
width:100%;
|
|
129
|
+
gap:12px;
|
|
130
|
+
display:flex;
|
|
127
131
|
border-top:1px solid #f2f4f7;
|
|
128
132
|
justify-content: flex-end;
|
|
129
133
|
}
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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 r from"react-dom/server";import{Icon as s}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 u}from"react/jsx-runtime";import{jsxs as _}from"react/jsx-runtime";export default class m{constructor(t={}){_defineProperty(this,"render",()=>_(u,{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,"removeModal",(t,e=!0)=>this._removeModal(t,e)),_defineProperty(this,"addAlert",(t={})=>{let{icon:e,type:o="",text:i="",subtext:r="",time:s=10,className:a,closeText:l="بستن"}=t;Alert({icon:e,type:o,text:i,subtext:r,time:s,className:a,closeText:l})}),_defineProperty(this,"addSnakebar",(t={})=>{let{text:e,index:o,type:i,subtext:r,action:s={},time:a=6,rtl:l}=t;this._addSnakebar({text:e,index:o,type:i,subtext:r,action:s,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:r,text:s,onSubmit:a,rtl:l=this.props.rtl,attrs:n={},onClose:p,backdrop:d,header:u,footer:_,closeType:m,body:c,id:$,mounted:g}=e;return h(Popup,{id:$,backdrop:d,footer:_,text:s,onSubmit:a,header:u,popover:i,position:r,rtl:l,attrs:n,closeType:m,body:c,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(u,{children:this.getModals()})}}class Popup extends e{constructor(t){super(t),this.dom=o(),this.backdropDom=o(),this.state={popoverStyle:void 0}}async onClose(){let{onClose:t}=this.props;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;return"object"==typeof e&&{html:h(ModalHeader,{rtl:t,header:e,handleClose:()=>this.onClose()}),className:"of-visible"}}body_layout(){let{body:t={}}=this.props;return{flex:1,html:h(ModalBody,{body:t,handleClose:this.onClose.bind(this),updatePopoverStyle:()=>this.updatePopoverStyle()})}}footer_layout(){let{closeText:t,submitText:e,onSubmit:o,footer:i,type:r}=this.props,s=this.onClose.bind(this);return{html:h(ModalFooter,{closeText:t,submitText:e,onSubmit:o,footer:i,type:r,handleClose:s})}}getBackDropClassName(){let{rtl:t,position:e="fullscreen",backdrop:o,mounted:i}=this.props,r="aio-popup-backdrop";return o&&o.attrs&&o.attrs.className&&(r+=" "+o.attrs.className),r+=` aio-popup-position-${e}`,r+=t?" rtl":" ltr",i||(r+=" not-mounted"),r}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:r,fitHorizontal:s,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:r,fitHorizontal:s,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:r}=this.state,s={...o?o.attrs:{},className:this.getBackDropClassName(),onClick:!1===o?void 0:t=>this.backClick(t)},a={...r,...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",{...s,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}){if("object"!=typeof e)return null;let{title:i,subtitle:r,buttons:d=[],onClose:u,backButton:_,attrs:m={}}=e,c="aio-popup-header"+(m.className?" "+m.className:""),$=m.style;return h(p,{layout:{attrs:m,className:c,style:$,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(s,{path:o,size:1}),align:"vh",onClick:()=>u(),style:i}}(),!!i&&(r?{flex:1,align:"v",column:[{html:i,className:"aio-popup-title"},{html:r,className:"aio-popup-subtitle"}]}:{flex:1,align:"v",html:i,className:"aio-popup-title"}),!!d.length&&{gap:6,align:"vh",row:()=>d.map(([t,e={}])=>{let{onClick:i=()=>{},className:r}=e;return e.className="aio-popup-header-button"+(r?" "+r:""),e.onClick=()=>i({close:o}),{html:h("button",{...e,children:t}),align:"vh"}})},!_&&!1!==u&&{html:h(s,{path:a,size:.8}),align:"vh",onClick(t){var e;return e=t,void(u?u(e):o())},className:"aio-popup-header-close-button"}]}})}function ModalBody(t){let{handleClose:e,body:o,updatePopoverStyle:r}=t,{render:s,attrs:a={}}=o,l="function"==typeof s?s({close:e}):s;return i(()=>{r()},[l]),h("div",{...a,className:"aio-popup-body"+(a.className?" "+a.className:""),children:"function"==typeof s&&l})}function ModalFooter({type:t,closeText:e="Close",submitText:o="Submit",footer:i,handleClose:r,onSubmit:s}){if("object"!=typeof i)return null;let{attrs:a={}}=i,{buttons:l=[]}=i,n
|
|
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 r from"react-dom/server";import{Icon as s}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 u}from"react/jsx-runtime";import{jsxs as _}from"react/jsx-runtime";export default class m{constructor(t={}){_defineProperty(this,"render",()=>_(u,{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,"removeModal",(t,e=!0)=>this._removeModal(t,e)),_defineProperty(this,"addAlert",(t={})=>{let{icon:e,type:o="",text:i="",subtext:r="",time:s=10,className:a,closeText:l="بستن"}=t;Alert({icon:e,type:o,text:i,subtext:r,time:s,className:a,closeText:l})}),_defineProperty(this,"addSnakebar",(t={})=>{let{text:e,index:o,type:i,subtext:r,action:s={},time:a=6,rtl:l}=t;this._addSnakebar({text:e,index:o,type:i,subtext:r,action:s,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:r,text:s,onSubmit:a,rtl:l=this.props.rtl,attrs:n={},onClose:p,backdrop:d,header:u,footer:_,closeType:m,body:c,id:$,mounted:g}=e;return h(Popup,{id:$,backdrop:d,footer:_,text:s,onSubmit:a,header:u,popover:i,position:r,rtl:l,attrs:n,closeType:m,body:c,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(u,{children:this.getModals()})}}class Popup extends e{constructor(t){super(t),this.dom=o(),this.backdropDom=o(),this.state={popoverStyle:void 0}}async onClose(){let{onClose:t}=this.props;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;return"object"==typeof e&&{html:h(ModalHeader,{rtl:t,header:e,handleClose:()=>this.onClose()}),className:"of-visible"}}body_layout(){let{body:t={}}=this.props;return{flex:1,html:h(ModalBody,{body:t,handleClose:this.onClose.bind(this),updatePopoverStyle:()=>this.updatePopoverStyle()})}}footer_layout(){let{closeText:t,submitText:e,onSubmit:o,footer:i,type:r}=this.props,s=this.onClose.bind(this);return{html:h(ModalFooter,{closeText:t,submitText:e,onSubmit:o,footer:i,type:r,handleClose:s})}}getBackDropClassName(){let{rtl:t,position:e="fullscreen",backdrop:o,mounted:i}=this.props,r="aio-popup-backdrop";return o&&o.attrs&&o.attrs.className&&(r+=" "+o.attrs.className),r+=` aio-popup-position-${e}`,r+=t?" rtl":" ltr",i||(r+=" not-mounted"),r}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:r,fitHorizontal:s,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:r,fitHorizontal:s,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:r}=this.state,s={...o?o.attrs:{},className:this.getBackDropClassName(),onClick:!1===o?void 0:t=>this.backClick(t)},a={...r,...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",{...s,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}){if("object"!=typeof e)return null;let{title:i,subtitle:r,buttons:d=[],onClose:u,backButton:_,attrs:m={}}=e,c="aio-popup-header"+(m.className?" "+m.className:""),$=m.style;return h(p,{layout:{attrs:m,className:c,style:$,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(s,{path:o,size:1}),align:"vh",onClick:()=>u(),style:i}}(),!!i&&(r?{flex:1,align:"v",column:[{html:i,className:"aio-popup-title"},{html:r,className:"aio-popup-subtitle"}]}:{flex:1,align:"v",html:i,className:"aio-popup-title"}),!!d.length&&{gap:6,align:"vh",row:()=>d.map(([t,e={}])=>{let{onClick:i=()=>{},className:r}=e;return e.className="aio-popup-header-button"+(r?" "+r:""),e.onClick=()=>i({close:o}),{html:h("button",{...e,children:t}),align:"vh"}})},!_&&!1!==u&&{html:h(s,{path:a,size:.8}),align:"vh",onClick(t){var e;return e=t,void(u?u(e):o())},className:"aio-popup-header-close-button"}]}})}function ModalBody(t){let{handleClose:e,body:o,updatePopoverStyle:r}=t,{render:s,attrs:a={}}=o,l="function"==typeof s?s({close:e}):s;return i(()=>{r()},[l]),h("div",{...a,className:"aio-popup-body"+(a.className?" "+a.className:""),children:"function"==typeof s&&l})}function ModalFooter({type:t,closeText:e="Close",submitText:o="Submit",footer:i,handleClose:r,onSubmit:s}){if("object"!=typeof i)return null;let{attrs:a={}}=i,{buttons:l=[]}=i,n;return h("div",{className:"aio-popup-footer"+(a.className?" "+a.className:""),style:a.style,children:l.length?l.map(([t,e={}])=>{let{onClick:o=()=>{},className:i}=e;return e.className="aio-popup-footer-button"+(i?" "+i:""),e.onClick=()=>o({close:r}),h("button",{...e,children:t})}):null})}function Alert(t={}){let{icon:e,type:o,text:i,subtext:s,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
2
|
<div class='aio-popup-alert-container ${p.id}${l?"aio-popup"+l:""}'>
|
|
3
3
|
<div class='aio-popup-alert aio-popup-alert-${o}'>
|
|
4
4
|
<div class='aio-popup-alert-header'>${p.getIcon()}</div>
|