aio-popup 4.5.0 → 4.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +2 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _react=_interopRequireWildcard(require("react")),ReactDOMServer=_interopRequireWildcard(require("react-dom/server")),_jquery=_interopRequireDefault(require("jquery"));require("./index.css");var _aioUtils=require("aio-utils"),_animeEs=_interopRequireDefault(require("animejs/lib/anime.es.js")),_jsxRuntime=require("react/jsx-runtime");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,i=new WeakMap;return(_getRequireWildcardCache=function(e){return e?i:t})(e)}function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var i=_getRequireWildcardCache(t);if(i&&i.has(e))return i.get(e);var r={__proto__:null},o=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if("default"!==n&&({}).hasOwnProperty.call(e,n)){var a=o?Object.getOwnPropertyDescriptor(e,n):null;a&&(a.get||a.set)?Object.defineProperty(r,n,a):r[n]=e[n]}return r.default=e,i&&i.set(e,r),r}function _defineProperty(e,t,i){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"==typeof t?t:t+""}function _toPrimitive(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}class AIOPopup{constructor(e){_defineProperty(this,"rtl",void 0),_defineProperty(this,"render",void 0),_defineProperty(this,"addModal",void 0),_defineProperty(this,"addHighlight",void 0),_defineProperty(this,"removeHighlight",void 0),_defineProperty(this,"addAlert",void 0),_defineProperty(this,"removeModal",void 0),_defineProperty(this,"addSnackebar",void 0),_defineProperty(this,"getModals",void 0),_defineProperty(this,"addConfirm",void 0),_defineProperty(this,"addPrompt",void 0),_defineProperty(this,"popupId",void 0),_defineProperty(this,"popupsRef",void 0),_defineProperty(this,"highlightRef",void 0);let{rtl:t=!1}=e||{};this.rtl=t,this.addSnackebar=()=>{},this.popupsRef=(0,_react.createRef)(),this.highlightRef=(0,_react.createRef)(),this.getModals=()=>{let e=this.popupsRef.current;return null===e?[]:e.getModals()||[]},this.addModal=e=>{let t=this.popupsRef.current;null!==t&&t.addModal(e)},this.addHighlight=e=>{let t=this.highlightRef.current;null!==t&&t.addHighlight(e)},this.removeModal=e=>{let t=this.popupsRef.current;null!==t&&t.removeModal(e)},this.removeHighlight=()=>{let e=this.highlightRef.current;null!==e&&e.removeHighlight()},this.render=()=>{let e={rtl:t,getActions:({add:e})=>this.addSnackebar=e};return(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(Popups,{rtl:t,ref:this.popupsRef}),(0,_jsxRuntime.jsx)(Snackebar,{...e}),(0,_jsxRuntime.jsx)(Highlight,{ref:this.highlightRef})]})},this.addAlert=e=>Alert(e),this.addConfirm=e=>{let{title:t,subtitle:i,text:r,submitText:o="Yes",canselText:n="No",onSubmit:a,onCansel:s=()=>{},setAttrs:l=()=>({})}=e,u={position:"center",setAttrs(e){let t=l(e);return"modal"===e?(0,_aioUtils.AddToAttrs)(t,{className:"aio-popup-confirm"}):t},header:{title:t,subtitle:i},body:()=>r,footer:()=>(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)("button",{type:"button",onClick:()=>{s(),this.removeModal()},children:n}),(0,_jsxRuntime.jsx)("button",{type:"button",className:"active",onClick:async()=>{if(a)!1!==await a()&&this.removeModal()},children:o})]})};this.addModal(u)},this.addPrompt=e=>{let{title:t,subtitle:i,text:r,submitText:o="Submit",canselText:n="close",onSubmit:a,onCansel:s=()=>{},setAttrs:l=()=>({})}=e,u={position:"center",setAttrs(e){let t=l(e);return"modal"===e?(0,_aioUtils.AddToAttrs)(t,{className:"aio-popup-prompt"}):t},state:{temp:""},header:{title:t,subtitle:i},body:({state:e,setState:t})=>(0,_jsxRuntime.jsx)("textarea",{placeholder:r,value:e.temp,onChange(e){t&&t({temp:e.target.value})}}),footer:({state:e,setState:t})=>(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)("button",{type:"button",onClick:()=>{s(),this.removeModal()},children:n}),(0,_jsxRuntime.jsx)("button",{type:"button",className:"active",onClick:async()=>{if(a)!1!==await a(e.temp)?this.removeModal():t({temp:""})},disabled:!e.temp,children:o})]})};this.addModal(u)}}}exports.default=AIOPopup;const Popups=(0,_react.forwardRef)((e,t)=>{let[i,r]=(0,_react.useState)([]),o=(0,_react.useRef)(i);o.current=i;let{rtl:n}=e;function a(e){void 0===e.id&&(e.id="popup"+Math.round(1e6*Math.random()));let t=e;r(i=>[...i.filter(({id:t})=>t!==e.id),t])}async function s(e="last"){if("all"===e){r([]);return}if(!o.current.length)return;"last"===e&&(e=o.current[o.current.length-1].id);let t=o.current.find(t=>t.id===e);t&&((0,_jquery.default)(`[data-id=${e}]`).addClass("not-mounted"),setTimeout(()=>{t&&"function"==typeof t.onClose&&t.onClose(),r(t=>t.filter(t=>t.id!==e))},300))}function l(){return o.current.map((e,t)=>(0,_jsxRuntime.jsx)(Popup,{modal:e,rtl:n,isLast:t===o.current.length-1,onClose:()=>s(e.id)},e.id))}(0,_react.useImperativeHandle)(t,()=>({addModal:a,removeModal:s,getModals:()=>o.current}));let u=l();return u.length?(0,_jsxRuntime.jsx)(_jsxRuntime.Fragment,{children:u}):null}),CTX=(0,_react.createContext)({});function Popup(e){let{modal:t,rtl:i,onClose:r,isLast:o}=e,{setAttrs:n=()=>({}),id:a,position:s="fullscreen",getTarget:l,maxHeight:u,fixStyle:d=e=>e}=t,[c]=(0,_react.useState)({dom:(0,_react.createRef)(),backdropDom:(0,_react.createRef)(),dui:void 0,isDown:!1}),[p,$]=(0,_react.useState)({}),[h,m]=(0,_react.useState)(t.state),_=n("modal")||{},f=n("backdrop")||{},g=(0,_react.useRef)(!1);async function x(){r()}function j(e){if(!c.dui)return;let t=(0,_jquery.default)(e.target);"popover"===s&&t.attr("data-id")!==c.dui&&!t.parents(`[data-id=${c.dui}]`).length&&x()}(0,_react.useEffect)(()=>()=>{(0,_jquery.default)(window).unbind("click",j)}),(0,_react.useEffect)(()=>{let e="popover"===s?function e(){if(!l)return{};let r=l();if(!r||!r.length)return{};let o={dom:(0,_jquery.default)(c.dom.current),target:r,fitHorizontal:t.fitHorizontal,fixStyle:d,pageSelector:t.pageSelector,limitTo:t.limitTo,attrs:_,rtl:i},n={...Align(o),position:"absolute"};return u&&(n.maxHeight=u),n}():{};if(console.log("updatedStyle.top",e.top),$(e),l){c.dui="a"+Math.round(1e7*Math.random());l().attr("data-id",c.dui)}setTimeout(()=>{let e=(0,_jquery.default)(c.dom.current);e.removeClass("not-mounted"),(0,_jquery.default)(c.backdropDom.current).removeClass("not-mounted"),e.focus()},0),(0,_jquery.default)(window).unbind("click",j),(0,_jquery.default)(window).bind("click",j)},[]);function v(e){if(o)27===e.keyCode&&r()}function y(){setTimeout(()=>c.isDown=!1,0)}let R,b,C,L;return(0,_jsxRuntime.jsx)(CTX.Provider,{value:{close:x,state:h,setState:m},children:(0,_jsxRuntime.jsx)("div",{...(R="aio-popup-backdrop",R+=` aio-popup-position-${s}`,R+=i?" rtl":" ltr",g&&(R+=" not-mounted"),(0,_aioUtils.AddToAttrs)(f,{className:R,attrs:{ref:c.backdropDom,onKeyDown:v,tabIndex:0,"data-id":a,onClick:f.onClick?f.onClick:function e(t){if(!c.isDown){t.stopPropagation();(0,_jquery.default)(t.target).hasClass("aio-popup-backdrop")&&x()}}}})),children:(0,_jsxRuntime.jsxs)("div",{...(b={...p,..._.style},C="ontouchstart"in document.documentElement?"onTouchStart":"onMouseDown",{..._,ref:c.dom,"data-id":t.id,tabIndex:0,onKeyDown:v,[C]:function e(t){(0,_jquery.default)(window).unbind("mouseup",y),(0,_jquery.default)(window).bind("mouseup",y),c.isDown=!0},className:(L="aio-popup",L+=i?" rtl":" ltr",g&&(L+=" not-mounted"),_.className&&(L+=" "+_.className),L),style:{...b}}),children:[!!t.header&&(0,_jsxRuntime.jsx)(ModalHeader,{modal:t}),(0,_jsxRuntime.jsx)(ModalBody,{modal:t}),!!t.footer&&(0,_jsxRuntime.jsx)("div",{...(0,_aioUtils.AddToAttrs)(n("footer"),{className:"aio-popup-footer"}),children:t.footer({state:h,setState:m,close:x})})]})})})}const ModalHeader=e=>{let t=(0,_react.useContext)(CTX),{modal:i}=e,{state:r,setState:o}=t,{setAttrs:n=()=>({})}=i,a=n("header")||{};if("function"==typeof i.header)return i.header({close:t.close,state:r,setState:o});if("object"!=typeof i.header)return null;let s="aio-popup-header",{title:l,subtitle:u,onClose:d,before:c,after:p}=i.header;function $(e){e.stopPropagation(),e.preventDefault(),"function"==typeof d?d({state:r,setState:o}):t.close()}function h(){return u?(0,_jsxRuntime.jsxs)("div",{className:`${s}-text`,children:[(0,_jsxRuntime.jsx)("div",{className:`${s}-title`,children:l}),(0,_jsxRuntime.jsx)("div",{className:`${s}-subtitle`,children:u})]}):(0,_jsxRuntime.jsx)("div",{className:`${s}-title`,style:{display:"flex",alignItems:"center",flex:1},children:l})}return(0,_jsxRuntime.jsxs)("div",{...(0,_aioUtils.AddToAttrs)(a,{className:s}),children:[void 0!==c&&(0,_jsxRuntime.jsx)("div",{className:`${s}-before`,onClick:e=>$(e),children:c}),!!l&&h(),void 0!==p&&(0,_jsxRuntime.jsx)("div",{className:`${s}-after`,onClick:e=>$(e),children:p}),!1!==d&&(0,_jsxRuntime.jsx)("div",{className:`${s}-close-button`,onClick:e=>$(e),children:(0,_jsxRuntime.jsx)(CloseIcon,{})})]})},ModalBody=e=>{let{state:t,setState:i,close:r}=(0,_react.useContext)(CTX),{modal:o}=e,{body:n=()=>null,setAttrs:a=()=>({})}=o,s=a("body")||{},l={close:r,state:t,setState:i},u=n(l);return u&&null!==u?(0,_jsxRuntime.jsx)("div",{...(0,_aioUtils.AddToAttrs)(s,{className:"aio-popup-body aio-popup-scroll"}),children:u}):null};function Alert(e){let{icon:t,type:i="",text:r="",subtext:o="",time:n=10,className:a,closeText:s="بستن",position:l="center",onClose:u}=e,d={id:"",time:0,getId:()=>"aa"+Math.round(1e8*Math.random()),getBarRender:()=>`<div class='aio-popup-time-bar' style="width:${d.time}%;"></div>`,updateBarRender(){(0,_jquery.default)(`.aio-popup-alert-container.${d.id} .aio-popup-time`).html(d.getBarRender())},getRender:()=>`
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _react=_interopRequireWildcard(require("react")),ReactDOMServer=_interopRequireWildcard(require("react-dom/server")),_jquery=_interopRequireDefault(require("jquery"));require("./index.css");var _animeEs=_interopRequireDefault(require("animejs/lib/anime.es.js")),_jsxRuntime=require("react/jsx-runtime");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,i=new WeakMap;return(_getRequireWildcardCache=function(e){return e?i:t})(e)}function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var i=_getRequireWildcardCache(t);if(i&&i.has(e))return i.get(e);var r={__proto__:null},o=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if("default"!==n&&({}).hasOwnProperty.call(e,n)){var a=o?Object.getOwnPropertyDescriptor(e,n):null;a&&(a.get||a.set)?Object.defineProperty(r,n,a):r[n]=e[n]}return r.default=e,i&&i.set(e,r),r}function _defineProperty(e,t,i){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"==typeof t?t:t+""}function _toPrimitive(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}class AIOPopup{constructor(e){_defineProperty(this,"rtl",void 0),_defineProperty(this,"render",void 0),_defineProperty(this,"addModal",void 0),_defineProperty(this,"addHighlight",void 0),_defineProperty(this,"removeHighlight",void 0),_defineProperty(this,"addAlert",void 0),_defineProperty(this,"removeModal",void 0),_defineProperty(this,"addSnackebar",void 0),_defineProperty(this,"getModals",void 0),_defineProperty(this,"addConfirm",void 0),_defineProperty(this,"addPrompt",void 0),_defineProperty(this,"popupId",void 0),_defineProperty(this,"popupsRef",void 0),_defineProperty(this,"highlightRef",void 0);let{rtl:t=!1}=e||{};this.rtl=t,this.addSnackebar=()=>{},this.popupsRef=(0,_react.createRef)(),this.highlightRef=(0,_react.createRef)(),this.getModals=()=>{let e=this.popupsRef.current;return null===e?[]:e.getModals()||[]},this.addModal=e=>{let t=this.popupsRef.current;null!==t&&t.addModal(e)},this.addHighlight=e=>{let t=this.highlightRef.current;null!==t&&t.addHighlight(e)},this.removeModal=e=>{let t=this.popupsRef.current;null!==t&&t.removeModal(e)},this.removeHighlight=()=>{let e=this.highlightRef.current;null!==e&&e.removeHighlight()},this.render=()=>{let e={rtl:t,getActions:({add:e})=>this.addSnackebar=e};return(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(Popups,{rtl:t,ref:this.popupsRef}),(0,_jsxRuntime.jsx)(Snackebar,{...e}),(0,_jsxRuntime.jsx)(Highlight,{ref:this.highlightRef})]})},this.addAlert=e=>Alert(e),this.addConfirm=e=>{let{title:t,subtitle:i,text:r,submitText:o="Yes",canselText:n="No",onSubmit:a,onCansel:s=()=>{},setAttrs:l=()=>({})}=e,u={position:"center",setAttrs(e){let t=l(e);return"modal"===e?AddToAttrs(t,{className:"aio-popup-confirm"}):t},header:{title:t,subtitle:i},body:()=>r,footer:()=>(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)("button",{type:"button",onClick:()=>{s(),this.removeModal()},children:n}),(0,_jsxRuntime.jsx)("button",{type:"button",className:"active",onClick:async()=>{if(a)!1!==await a()&&this.removeModal()},children:o})]})};this.addModal(u)},this.addPrompt=e=>{let{title:t,subtitle:i,text:r,submitText:o="Submit",canselText:n="close",onSubmit:a,onCansel:s=()=>{},setAttrs:l=()=>({})}=e,u={position:"center",setAttrs(e){let t=l(e);return"modal"===e?AddToAttrs(t,{className:"aio-popup-prompt"}):t},state:{temp:""},header:{title:t,subtitle:i},body:({state:e,setState:t})=>(0,_jsxRuntime.jsx)("textarea",{placeholder:r,value:e.temp,onChange(e){t&&t({temp:e.target.value})}}),footer:({state:e,setState:t})=>(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)("button",{type:"button",onClick:()=>{s(),this.removeModal()},children:n}),(0,_jsxRuntime.jsx)("button",{type:"button",className:"active",onClick:async()=>{if(a)!1!==await a(e.temp)?this.removeModal():t({temp:""})},disabled:!e.temp,children:o})]})};this.addModal(u)}}}exports.default=AIOPopup;const Popups=(0,_react.forwardRef)((e,t)=>{let[i,r]=(0,_react.useState)([]),o=(0,_react.useRef)(i);o.current=i;let{rtl:n}=e;function a(e){void 0===e.id&&(e.id="popup"+Math.round(1e6*Math.random()));let t=e;r(i=>[...i.filter(({id:t})=>t!==e.id),t])}async function s(e="last"){if("all"===e){r([]);return}if(!o.current.length)return;"last"===e&&(e=o.current[o.current.length-1].id);let t=o.current.find(t=>t.id===e);t&&((0,_jquery.default)(`[data-id=${e}]`).addClass("not-mounted"),setTimeout(()=>{t&&"function"==typeof t.onClose&&t.onClose(),r(t=>t.filter(t=>t.id!==e))},300))}function l(){return o.current.map((e,t)=>(0,_jsxRuntime.jsx)(Popup,{modal:e,rtl:n,isLast:t===o.current.length-1,onClose:()=>s(e.id)},e.id))}(0,_react.useImperativeHandle)(t,()=>({addModal:a,removeModal:s,getModals:()=>o.current}));let u=l();return u.length?(0,_jsxRuntime.jsx)(_jsxRuntime.Fragment,{children:u}):null}),CTX=(0,_react.createContext)({});function Popup(e){let{modal:t,rtl:i,onClose:r,isLast:o}=e,{setAttrs:n=()=>({}),id:a,position:s="fullscreen",getTarget:l,maxHeight:u,fixStyle:d=e=>e}=t,[c]=(0,_react.useState)({dom:(0,_react.createRef)(),backdropDom:(0,_react.createRef)(),dui:void 0,isDown:!1}),[p,$]=(0,_react.useState)({}),[h,m]=(0,_react.useState)(t.state),_=n("modal")||{},f=n("backdrop")||{},g=(0,_react.useRef)(!1);async function x(){r()}function j(e){if(!c.dui)return;let t=(0,_jquery.default)(e.target);"popover"===s&&t.attr("data-id")!==c.dui&&!t.parents(`[data-id=${c.dui}]`).length&&x()}(0,_react.useEffect)(()=>()=>{(0,_jquery.default)(window).unbind("click",j)}),(0,_react.useEffect)(()=>{let e="popover"===s?function e(){if(!l)return{};let r=l();if(!r||!r.length)return{};let o={dom:(0,_jquery.default)(c.dom.current),target:r,fitHorizontal:t.fitHorizontal,fixStyle:d,pageSelector:t.pageSelector,limitTo:t.limitTo,attrs:_,rtl:i},n={...Align(o),position:"absolute"};return u&&(n.maxHeight=u),n}():{};if(console.log("updatedStyle.top",e.top),$(e),l){c.dui="a"+Math.round(1e7*Math.random());l().attr("data-id",c.dui)}setTimeout(()=>{let e=(0,_jquery.default)(c.dom.current);e.removeClass("not-mounted"),(0,_jquery.default)(c.backdropDom.current).removeClass("not-mounted"),e.focus()},0),(0,_jquery.default)(window).unbind("click",j),(0,_jquery.default)(window).bind("click",j)},[]);function v(e){if(o)27===e.keyCode&&r()}function y(){setTimeout(()=>c.isDown=!1,0)}let R,b,C,L;return(0,_jsxRuntime.jsx)(CTX.Provider,{value:{close:x,state:h,setState:m},children:(0,_jsxRuntime.jsx)("div",{...(R="aio-popup-backdrop",R+=` aio-popup-position-${s}`,R+=i?" rtl":" ltr",g&&(R+=" not-mounted"),AddToAttrs(f,{className:R,attrs:{ref:c.backdropDom,onKeyDown:v,tabIndex:0,"data-id":a,onClick:f.onClick?f.onClick:function e(t){if(!c.isDown){t.stopPropagation();(0,_jquery.default)(t.target).hasClass("aio-popup-backdrop")&&x()}}}})),children:(0,_jsxRuntime.jsxs)("div",{...(b={...p,..._.style},C="ontouchstart"in document.documentElement?"onTouchStart":"onMouseDown",{..._,ref:c.dom,"data-id":t.id,tabIndex:0,onKeyDown:v,[C]:function e(t){(0,_jquery.default)(window).unbind("mouseup",y),(0,_jquery.default)(window).bind("mouseup",y),c.isDown=!0},className:(L="aio-popup",L+=i?" rtl":" ltr",g&&(L+=" not-mounted"),_.className&&(L+=" "+_.className),L),style:{...b}}),children:[!!t.header&&(0,_jsxRuntime.jsx)(ModalHeader,{modal:t}),(0,_jsxRuntime.jsx)(ModalBody,{modal:t}),!!t.footer&&(0,_jsxRuntime.jsx)("div",{...AddToAttrs(n("footer"),{className:"aio-popup-footer"}),children:t.footer({state:h,setState:m,close:x})})]})})})}const ModalHeader=e=>{let t=(0,_react.useContext)(CTX),{modal:i}=e,{state:r,setState:o}=t,{setAttrs:n=()=>({})}=i,a=n("header")||{};if("function"==typeof i.header)return i.header({close:t.close,state:r,setState:o});if("object"!=typeof i.header)return null;let s="aio-popup-header",{title:l,subtitle:u,onClose:d,before:c,after:p}=i.header;function $(e){e.stopPropagation(),e.preventDefault(),"function"==typeof d?d({state:r,setState:o}):t.close()}function h(){return u?(0,_jsxRuntime.jsxs)("div",{className:`${s}-text`,children:[(0,_jsxRuntime.jsx)("div",{className:`${s}-title`,children:l}),(0,_jsxRuntime.jsx)("div",{className:`${s}-subtitle`,children:u})]}):(0,_jsxRuntime.jsx)("div",{className:`${s}-title`,style:{display:"flex",alignItems:"center",flex:1},children:l})}return(0,_jsxRuntime.jsxs)("div",{...AddToAttrs(a,{className:s}),children:[void 0!==c&&(0,_jsxRuntime.jsx)("div",{className:`${s}-before`,onClick:e=>$(e),children:c}),!!l&&h(),void 0!==p&&(0,_jsxRuntime.jsx)("div",{className:`${s}-after`,onClick:e=>$(e),children:p}),!1!==d&&(0,_jsxRuntime.jsx)("div",{className:`${s}-close-button`,onClick:e=>$(e),children:(0,_jsxRuntime.jsx)(CloseIcon,{})})]})},ModalBody=e=>{let{state:t,setState:i,close:r}=(0,_react.useContext)(CTX),{modal:o}=e,{body:n=()=>null,setAttrs:a=()=>({})}=o,s=a("body")||{},l={close:r,state:t,setState:i},u=n(l);return u&&null!==u?(0,_jsxRuntime.jsx)("div",{...AddToAttrs(s,{className:"aio-popup-body aio-popup-scroll"}),children:u}):null};function Alert(e){let{icon:t,type:i="",text:r="",subtext:o="",time:n=10,className:a,closeText:s="بستن",position:l="center",onClose:u}=e,d={id:"",time:0,getId:()=>"aa"+Math.round(1e8*Math.random()),getBarRender:()=>`<div class='aio-popup-time-bar' style="width:${d.time}%;"></div>`,updateBarRender(){(0,_jquery.default)(`.aio-popup-alert-container.${d.id} .aio-popup-time`).html(d.getBarRender())},getRender:()=>`
2
2
  <div class='aio-popup-alert-container not-mounted ${d.id} aio-popup-alert-container-${l}${a?` ${a}`:""}'>
3
3
  <div class='aio-popup-alert aio-popup-alert-${i}'>
4
4
  <div class='aio-popup-alert-header'>${d.getIcon()}</div>
@@ -14,4 +14,4 @@
14
14
  </div>
15
15
  `,close(){d.toggleClass(!1),setTimeout(()=>{"function"==typeof u&&u(),!1!==u&&(0,_jquery.default)("."+d.id).remove()},200)},getIcon:()=>!1===t?"":t||({error:'<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z"></path></svg>',warning:'<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M12,2L1,21H23M12,6L19.53,19H4.47M11,10V14H13V10M11,16V18H13V16"></path></svg>',info:'<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z"></path></svg>',success:'<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M12 20C7.59 20 4 16.41 4 12S7.59 4 12 4 20 7.59 20 12 16.41 20 12 20M16.59 7.58L10 14.17L7.41 11.59L6 13L10 17L18 9L16.59 7.58Z"></path></svg>'})[i]||"",startTimer(){setTimeout(()=>{if(d.time>=100){d.time=100,d.close();return}d.time+=2,d.updateBarRender(),d.startTimer()},n/50*1e3)},toggleClass(e){let t=(0,_jquery.default)(`.${d.id}`);e?setTimeout(()=>t.removeClass("not-mounted"),0):t.addClass("not-mounted")},render(){(0,_jquery.default)("body").append(d.getRender()),(0,_jquery.default)("button."+d.id).off("click",d.close),(0,_jquery.default)("button."+d.id).on("click",d.close),d.toggleClass(!0)}};d.id=d.getId(),d.render(),n&&d.startTimer()}class Snackebar extends _react.Component{constructor(e){super(e),this.state={items:[]},e.getActions({add:this.add.bind(this)})}add(e){let{items:t}=this.state,i=[...t,{...e,id:"a"+Math.round(1e9*Math.random())}];this.setState({items:i})}remove(e,t){if(!1===t)return;let{items:i}=this.state,r=i.filter((t,i)=>t.id!==e);this.setState({items:r}),"function"==typeof t&&t()}render(){let{items:e}=this.state,{rtl:t}=this.props;return(0,_jsxRuntime.jsx)(_jsxRuntime.Fragment,{children:e.map((e,i)=>(0,_react.createElement)(SnackebarItem,{rtl:t,item:e,index:i,onRemove:t=>this.remove(t,e.onClose),key:e.id}))})}}function SnackebarItem(e){var t;let{item:i,onRemove:r,index:o,rtl:n}=e,{time:a=8,id:s,text:l,type:u,subtext:d,action:c,onClose:p,verticalAlign:$="end",horizontalAlign:h="center",icon:m,attrs:_={}}=i;"start"!==$&&"end"!==$&&($="end",console.error('aio-popup error => snackebar item .verticalAlign should be "start" or "end"')),"start"!==h&&"end"!==h&&"center"!==h&&(h="center",console.error('aio-popup error => snackebar item .horizontalAlign should be "start" or "end" or "center"'));let[f,g]=(0,_react.useState)(!1);function x(){g(!1),setTimeout(()=>{r(s)},200)}(0,_react.useEffect)(()=>{setTimeout(()=>g(!0),0),setTimeout(()=>x(),1e3*a)},[]);let j,v,y,R,b;return j="aio-popup-snackebar-item-container",j+=` aio-popup-snackebar-item-container-horizontal-align-${h}`,f&&(j+=" mounted"),n&&(j+=" rtl"),v=function e(t){let i=(0,_jquery.default)(".aio-popup-snackebar-item-container"),r={start:12,end:12};for(let o=0;o<t;o++){let n=i.eq(o),a=n.height()+6,s=n.attr("data-vertical-align");r[s]+=a}return{["start"===$?"top":"bottom"]:r[$]}}(o),y={"data-vertical-align":$,className:j,style:v,onClick:!1===p?void 0:()=>x()},(0,_jsxRuntime.jsx)("div",{...y,children:(R="aio-popup-snackebar-item",R+=` aio-popup-snackebar-item-${u}`,_.className&&(R+=` ${_.className}`),b={..._,className:R,style:_.style},(0,_jsxRuntime.jsxs)("div",{...b,children:[(0,_jsxRuntime.jsx)("div",{className:"aio-popup-snackebar-item-icon",children:m||("error"===(t=u)||"warning"===t||"info"===t?(0,_jsxRuntime.jsx)("svg",{viewBox:"0 0 24 24",role:"presentation",style:{width:"1.2rem",height:"1.2rem"},children:(0,_jsxRuntime.jsx)("path",{d:"M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z",style:{fill:"currentcolor"}})}):(0,_jsxRuntime.jsx)("svg",{viewBox:"0 0 24 24",role:"presentation",style:{width:"1.2rem",height:"1.2rem"},children:(0,_jsxRuntime.jsx)("path",{d:"M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M12 20C7.59 20 4 16.41 4 12S7.59 4 12 4 20 7.59 20 12 16.41 20 12 20M16.59 7.58L10 14.17L7.41 11.59L6 13L10 17L18 9L16.59 7.58Z",style:{fill:"currentcolor"}})}))})," ",(0,_jsxRuntime.jsxs)("div",{className:"aio-popup-snackebar-item-text",children:[(0,_jsxRuntime.jsx)("div",{className:"aio-popup-snackebar-item-uptext",children:l}),!!d&&(0,_jsxRuntime.jsx)("div",{className:"aio-popup-snackebar-item-subtext",children:d})]})," ",c&&c.text?(0,_jsxRuntime.jsx)("button",{className:"aio-popup-snackebar-item-action",onClick(e){e.stopPropagation(),c&&c.onClick(),x()},children:c.text}):null," ",(0,_jsxRuntime.jsx)("div",{className:"aio-popup-snackebar-bar",style:{transition:`${a}s linear`}})," "]}))})}function Align(e){let{dom:t,target:i,fitHorizontal:r,fixStyle:o=e=>e,attrs:n={},pageSelector:a,rtl:s,limitTo:l}=e,u={getDomLimit(e,t){let i=e.offset(),r=i.left-window.pageXOffset,o=i.top-window.pageYOffset;if(a&&"page"!==t){let n=(0,_jquery.default)(a);try{let{left:s,top:l}=n.offset()||{left:0,top:0};s-=window.scrollX,l-=window.scrollY,r-=s,o-=l}catch{}}let u=e.outerWidth(),d=e.outerHeight(),c=r+u,p=o+d;return{left:r,top:o,right:c,bottom:p,width:u,height:d}},getPageLimit(){let e=a?(0,_jquery.default)(a):void 0;e=Array.isArray(e)&&0===e.length?void 0:e;let t=window.innerWidth,i=window.innerHeight,r=e?u.getDomLimit(e,"page"):{left:0,top:0,right:t,bottom:i};return r.left<0&&(r.left=0),r.right>t&&(r.right=t),r.top<0&&(r.top=0),r.bottom>i&&(r.bottom=i),r},getRelatedToLmit(){if(!l)return;let e=t.parents(l);if(!e.length)return;let i=e.offset(),r=i.left-window.pageXOffset,o=i.top-window.pageYOffset,n=e.outerWidth(),a=e.outerHeight();return{left:r,top:o,right:r+n,bottom:o+a,width:n,height:a}},align(){let e=u.getPageLimit(),a=u.getDomLimit(i,"target"),l=u.getDomLimit(t,"popover"),d;if(l.top=a.bottom,l.bottom=l.top+l.height,r)l.width=a.width,l.left=a.left,l.right=a.left+a.width;else{let c=u.getRelatedToLmit()||e;s?(l.right=a.right,l.left=l.right-l.width,l.left<c.left&&(l.left=c.left)):(l.left=a.left,l.right=l.left+l.width,l.right>c.right&&(l.left=c.right-l.width))}return l.bottom>e.bottom?l.height>a.top-e.top?l.top=e.bottom-l.height:l.top=a.top-l.height:l.top=a.bottom,l.height>e.bottom-e.top&&(l.top=6,l.bottom=void 0,l.height=e.bottom-e.top-12,d="auto"),o({left:l.left,top:l.top,width:l.width,overflowY:d,...n.style},{targetLimit:a,pageLimit:e})}};return u.align()}const Highlight=(0,_react.forwardRef)((e,t)=>{let[i,r]=(0,_react.useState)(!1),[o,n]=(0,_react.useState)({Left:0,Top:0,Width:0,Height:0,TopSpace:0,BottomSpace:0}),a=(0,_react.useRef)(),s=a.current,l=(0,_react.useRef)(o);function u(e){let t=_("padding",6),i=e.offset(),r=i.left-window.pageXOffset,o=i.top-window.pageYOffset,n=window.innerHeight,a=e.outerWidth(),s=e.outerHeight();return{Left:r-1*t,Top:o-1*t,Width:a+2*t,Height:s+2*t,TopSpace:o,BottomSpace:n-(o+s)}}function d(){let e=_("easing",void 0);var t=["linear","easeInQuad","easeInSine","easeInCirc","easeInBack","easeOutQuad","easeOutSine","easeOutCirc","easeInOutQuad","easeInOutSine","easeInOutBack","easeOutBounce"];return"number"==typeof e?t[e]||t[0]:e}function c(){n({Left:0,Top:0,Width:0,Height:0,TopSpace:0,BottomSpace:0}),r(!1)}function p(e){let{dom:t}=e;a.current=e,r(!0),setTimeout(()=>{try{let e=_("duration",1200);t[0].scrollIntoView();let i=u(t),r=d(),o={...i,targets:[{...l.current}],duration:e,update(e){let{animatables:t}=e;n({...t[0].target})}};r&&(o.easing=r),(0,_animeEs.default)(o)}catch{alert(`
16
16
  aio-highlighter error => connot find dom
17
- `)}},0)}function $(e){return(0,_jsxRuntime.jsx)("svg",{version:"1.1",id:"Layer_1",xmlns:"http://www.w3.org/2000/svg",x:"0px",y:"0px",viewBox:"0 0 512 512",...e,children:(0,_jsxRuntime.jsxs)("g",{children:[(0,_jsxRuntime.jsx)("path",{d:"M242.1,45.2c7.7-7.7,20.2-7.7,27.8-0.1l0.1,0.1l236.3,236.3c7.7,7.7,7.7,20.2,0,27.9c-7.7,7.7-20.2,7.7-27.9,0 L256,86.9L33.7,309.3c-7.7,7.7-20.2,7.7-27.9,0c-7.7-7.7-7.7-20.2,0-27.9L242.1,45.2z"}),(0,_jsxRuntime.jsx)("path",{d:"M242.1,202.7c7.7-7.7,20.2-7.7,27.8-0.1l0.1,0.1L506.2,439c7.7,7.7,7.7,20.2,0,27.9c-7.7,7.7-20.2,7.7-27.9,0 L256,244.5L33.7,466.9c-7.7,7.7-20.2,7.7-27.9,0c-7.7-7.7-7.7-20.2,0-27.9L242.1,202.7z"})]})})}function h(e,t,i){let r={width:24,height:24,style:{position:"absolute",height:24,width:24,left:t+i/2-12},className:`aio-popup-highlight-arrow-${e}`};return(0,_jsxRuntime.jsx)("div",{className:"aio-popup-highlight-arrow",children:$(r)})}function m(e){if(!s||!s.html)return"";let t,i=s.html||"",r=(0,_jsxRuntime.jsx)("div",{className:"aio-popup-highlight-space"}),o=(0,_jsxRuntime.jsx)("div",{className:"aio-popup-highlight-html",children:i}),n=h(e,l.current.Left,l.current.Width);return t="top"===e?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[r,o,n]}):(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[n,o,r]}),(0,_jsxRuntime.jsx)("div",{className:"aio-popup-highlight-html-container",children:t})}function _(e,t){if(!s||null===s)return t;let i=s[e];return void 0===i?t:i}function f(){!_("mouseAccess",!1)&&null!=s&&s.onClick&&s.onClick()}function g(e){let t="",i=0,r="aio-popup-highlight-mask",o=l.current;return"top"===e?(i=o.Top,o.TopSpace>o.BottomSpace&&(t=m("top"))):"bottom"===e?(r+=" aio-popup-highlight-mask-flex",o.TopSpace<=o.BottomSpace&&(t=m("bottom"))):"left"===e?i=o.Left:r+=" aio-popup-highlight-mask-flex",(0,_jsxRuntime.jsx)("div",{className:r,style:{["top"===e||"bottom"===e?"height":"width"]:i},onClick:()=>f(),children:t})}function x(){let e=_("mouseAccess",!1);return(0,_jsxRuntime.jsx)("div",{style:{width:o.Width},className:"aio-popup-highlight-focus-container",onClick:e?void 0:()=>f(),children:(0,_jsxRuntime.jsx)("div",{className:"aio-popup-highlight-focus"})})}function j(){return(0,_jsxRuntime.jsxs)("div",{className:"aio-popup-highlight-main",style:{height:o.Height},children:[g("left"),x(),g("right")]})}if(l.current=o,(0,_react.useImperativeHandle)(t,()=>({addHighlight:p,removeHighlight:c})),!i)return null;function v(){let e=_("mouseAccess",!1);return{pointerEvents:e?"none":"all"}}let y=(0,_aioUtils.AddToAttrs)(_("attrs",{}),{className:"aio-popup-highlight",style:v()});return(0,_jsxRuntime.jsxs)("div",{...y,children:[g("top"),j(),g("bottom")]})}),CloseIcon=()=>(0,_jsxRuntime.jsx)("svg",{viewBox:"0 0 24 24",role:"presentation",style:{width:"1.2rem",height:"1.2rem"},children:(0,_jsxRuntime.jsx)("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",style:{fill:"currentcolor"}})});
17
+ `)}},0)}function $(e){return(0,_jsxRuntime.jsx)("svg",{version:"1.1",id:"Layer_1",xmlns:"http://www.w3.org/2000/svg",x:"0px",y:"0px",viewBox:"0 0 512 512",...e,children:(0,_jsxRuntime.jsxs)("g",{children:[(0,_jsxRuntime.jsx)("path",{d:"M242.1,45.2c7.7-7.7,20.2-7.7,27.8-0.1l0.1,0.1l236.3,236.3c7.7,7.7,7.7,20.2,0,27.9c-7.7,7.7-20.2,7.7-27.9,0 L256,86.9L33.7,309.3c-7.7,7.7-20.2,7.7-27.9,0c-7.7-7.7-7.7-20.2,0-27.9L242.1,45.2z"}),(0,_jsxRuntime.jsx)("path",{d:"M242.1,202.7c7.7-7.7,20.2-7.7,27.8-0.1l0.1,0.1L506.2,439c7.7,7.7,7.7,20.2,0,27.9c-7.7,7.7-20.2,7.7-27.9,0 L256,244.5L33.7,466.9c-7.7,7.7-20.2,7.7-27.9,0c-7.7-7.7-7.7-20.2,0-27.9L242.1,202.7z"})]})})}function h(e,t,i){let r={width:24,height:24,style:{position:"absolute",height:24,width:24,left:t+i/2-12},className:`aio-popup-highlight-arrow-${e}`};return(0,_jsxRuntime.jsx)("div",{className:"aio-popup-highlight-arrow",children:$(r)})}function m(e){if(!s||!s.html)return"";let t,i=s.html||"",r=(0,_jsxRuntime.jsx)("div",{className:"aio-popup-highlight-space"}),o=(0,_jsxRuntime.jsx)("div",{className:"aio-popup-highlight-html",children:i}),n=h(e,l.current.Left,l.current.Width);return t="top"===e?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[r,o,n]}):(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[n,o,r]}),(0,_jsxRuntime.jsx)("div",{className:"aio-popup-highlight-html-container",children:t})}function _(e,t){if(!s||null===s)return t;let i=s[e];return void 0===i?t:i}function f(){!_("mouseAccess",!1)&&null!=s&&s.onClick&&s.onClick()}function g(e){let t="",i=0,r="aio-popup-highlight-mask",o=l.current;return"top"===e?(i=o.Top,o.TopSpace>o.BottomSpace&&(t=m("top"))):"bottom"===e?(r+=" aio-popup-highlight-mask-flex",o.TopSpace<=o.BottomSpace&&(t=m("bottom"))):"left"===e?i=o.Left:r+=" aio-popup-highlight-mask-flex",(0,_jsxRuntime.jsx)("div",{className:r,style:{["top"===e||"bottom"===e?"height":"width"]:i},onClick:()=>f(),children:t})}function x(){let e=_("mouseAccess",!1);return(0,_jsxRuntime.jsx)("div",{style:{width:o.Width},className:"aio-popup-highlight-focus-container",onClick:e?void 0:()=>f(),children:(0,_jsxRuntime.jsx)("div",{className:"aio-popup-highlight-focus"})})}function j(){return(0,_jsxRuntime.jsxs)("div",{className:"aio-popup-highlight-main",style:{height:o.Height},children:[g("left"),x(),g("right")]})}if(l.current=o,(0,_react.useImperativeHandle)(t,()=>({addHighlight:p,removeHighlight:c})),!i)return null;function v(){let e=_("mouseAccess",!1);return{pointerEvents:e?"none":"all"}}let y=AddToAttrs(_("attrs",{}),{className:"aio-popup-highlight",style:v()});return(0,_jsxRuntime.jsxs)("div",{...y,children:[g("top"),j(),g("bottom")]})}),CloseIcon=()=>(0,_jsxRuntime.jsx)("svg",{viewBox:"0 0 24 24",role:"presentation",style:{width:"1.2rem",height:"1.2rem"},children:(0,_jsxRuntime.jsx)("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",style:{fill:"currentcolor"}})});function AddToAttrs(e,t){let{style:i}=t,r,o=[...(e=e||{}).className?e.className.split(" "):[],...(t.className?Array.isArray(t.className)?t.className:t.className.split(" "):[]).filter(e=>!!e)],n=o.length?o.join(" "):void 0,a={...e.style,...i};return{...e,className:n,style:a,...t.attrs}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-popup",
3
- "version": "4.5.0",
3
+ "version": "4.5.1",
4
4
  "description": "handle all types of popup and modals in react",
5
5
  "main": "index.js",
6
6
  "scripts": {