aio-popup 5.0.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/index.css +70 -1
  2. package/index.d.ts +12 -15
  3. package/index.js +803 -15
  4. package/package.json +1 -1
package/index.css CHANGED
@@ -812,4 +812,73 @@
812
812
  font-weight:bold;
813
813
  border-radius:6px;
814
814
  border:1px solid #eee;
815
- } */
815
+ } */
816
+ .aio-loading {
817
+ z-index: 100000000000000000000000000000;
818
+ position: absolute;
819
+ direction: ltr;
820
+ width: 100%;
821
+ height: 100%;
822
+ top: 0;
823
+ left: 0;
824
+ display: flex;
825
+ align-items: center;
826
+ align-items: center;
827
+ justify-content: center;
828
+ }
829
+
830
+ .aio-loading-container-0 {
831
+ border-radius: 12px;
832
+ height: 72px;
833
+ width: 72px;
834
+ display: flex;
835
+ align-items: center;
836
+ justify-content: center;
837
+ background: rgba(0, 0, 0, 0.7);
838
+ opacity: 1;
839
+ animation-name: aioloadingopacity;
840
+ animation-duration: 2s;
841
+ animation-fill-mode: forwards;
842
+ }
843
+
844
+ .aio-loading-0 {
845
+ width: 60px;
846
+ display: flex;
847
+ align-items: center;
848
+ justify-content: center;
849
+ }
850
+
851
+ .aio-loading-item-0 {
852
+ width: 4px;
853
+ height: 36px;
854
+ background: rgb(255, 255, 255);
855
+ margin: 0px 1.5px;
856
+ border-radius: 0px;
857
+ }
858
+
859
+ @keyframes aioloading0 {
860
+
861
+ 0%,
862
+ 40%,
863
+ 100% {
864
+ transform: scaleY(0.4);
865
+ }
866
+
867
+ 20% {
868
+ transform: scaleY(1.0);
869
+ }
870
+ }
871
+
872
+ @keyframes aioloadingopacity {
873
+ 0% {
874
+ opacity: 0;
875
+ }
876
+
877
+ 50% {
878
+ opacity: 0;
879
+ }
880
+
881
+ 100% {
882
+ opacity: 1;
883
+ }
884
+ }
package/index.d.ts CHANGED
@@ -16,16 +16,6 @@ export type AP_header = ((p: {
16
16
  setState: (state: any) => void;
17
17
  }) => void);
18
18
  };
19
- export type AP_body = (p: {
20
- removeModal: () => void;
21
- state: any;
22
- setState: (state: any) => void;
23
- }) => ReactNode;
24
- export type AP_footer = (p: {
25
- state: any;
26
- setState: (v: any) => void;
27
- removeModal: () => void;
28
- }) => ReactNode;
29
19
  type AP_setAttrs = (mode: AP_attrsKey) => any;
30
20
  export type AP_modal = {
31
21
  getTarget?: () => any;
@@ -36,8 +26,8 @@ export type AP_modal = {
36
26
  position?: AP_position;
37
27
  header?: AP_header;
38
28
  state?: any;
39
- footer?: AP_footer;
40
- body?: AP_body;
29
+ footer?: ReactNode;
30
+ body: ReactNode;
41
31
  animate?: boolean;
42
32
  fitHorizontal?: boolean;
43
33
  setAttrs?: AP_setAttrs;
@@ -81,7 +71,6 @@ export type AP_highlight = {
81
71
  export type AP_confirm = {
82
72
  title?: string;
83
73
  subtitle?: string;
84
- text?: ReactNode;
85
74
  submitText?: string;
86
75
  canselText?: string;
87
76
  onSubmit?: () => Promise<boolean>;
@@ -91,7 +80,6 @@ export type AP_confirm = {
91
80
  export type AP_prompt = {
92
81
  title?: string;
93
82
  subtitle?: string;
94
- text?: string;
95
83
  submitText?: string;
96
84
  canselText?: string;
97
85
  onSubmit?: (text: string) => Promise<boolean>;
@@ -107,7 +95,7 @@ type AP_removeHighlight = () => void;
107
95
  type AP_getModals = () => AP_modal[];
108
96
  type AP_addConfirm = (item: AP_confirm) => void;
109
97
  type AP_addPrompt = (item: AP_prompt) => void;
110
- type AP_render = () => ReactNode;
98
+ type AP_render = (caller?: string) => ReactNode;
111
99
  export type AP_usePopup = {
112
100
  addAlert: AP_addAlert;
113
101
  addSnackebar: AP_addSnackebar;
@@ -144,3 +132,12 @@ export type AP_SnackebarItem = {
144
132
  };
145
133
  export declare function Alert(props: AP_alert): void;
146
134
  type AP_easing = 'linear' | 'easeInQuad' | 'easeInCubic' | 'easeInQuart' | 'easeInQuint' | 'easeInSine' | 'easeInExpo' | 'easeInCirc' | 'easeInBack' | 'easeOutQuad' | 'easeOutCubic' | 'easeOutQuart' | 'easeOutQuint' | 'easeOutSine' | 'easeOutExpo' | 'easeOutCirc' | 'easeOutBack' | 'easeInBounce' | 'easeInOutQuad' | 'easeInOutCubic' | 'easeInOutQuart' | 'easeInOutQuint' | 'easeInOutSine' | 'easeInOutExpo' | 'easeInOutCirc' | 'easeInOutBack' | 'easeInOutBounce' | 'easeOutBounce' | 'easeOutInQuad' | 'easeOutInCubic' | 'easeOutInQuart' | 'easeOutInQuint' | 'easeOutInSine' | 'easeOutInExpo' | 'easeOutInCirc' | 'easeOutInBack' | 'easeOutInBounce';
135
+ export declare class Loading {
136
+ loader: any;
137
+ constructor(loader?: string);
138
+ private getLoader_0;
139
+ private getLoaderItem_0;
140
+ getLoader: (id: string) => string;
141
+ show: (id: string, parentSelector?: string) => void;
142
+ hide: (id: string) => void;
143
+ }
package/index.js CHANGED
@@ -1,15 +1,803 @@
1
- import{createRef as t,useEffect as e,useState as o,createContext as i,useContext as r,useRef as a}from"react";import*as n from"react-dom/server";import l from"react-dom";import d from"animejs/lib/anime.es.js";import s from"jquery";import"./index.css";import{jsx as p}from"react/jsx-runtime";import{Fragment as c}from"react/jsx-runtime";import{jsxs as u}from"react/jsx-runtime";let CTX=i({});function Align(t){let{modal:e,target:o,fitHorizontal:i,rtl:r,limitTo:a}=t,n=window.innerWidth,l=window.innerHeight,d={left:0,top:0,bottom:l,right:n,width:n,height:l},s=getBound(o[0]),p=getBound(e[0]);s={...s};let c;if((p={...p}).top=s.bottom,p.bottom=p.top+p.height,i)p.width=s.width,p.left=s.left,p.right=s.left+s.width;else{if(a){let u=e.parents(a);u.length&&(d=getBound(u[0]))}r?(p.right=s.right,p.left=p.right-p.width,p.left<d.left&&(p.left=d.left)):(p.left=s.left,p.right=p.left+p.width,p.right>d.right&&(p.left=d.right-p.width))}return p.bottom>d.bottom?p.height>s.top-d.top?p.top=d.bottom-p.height:p.top=s.top-p.height:p.top=s.bottom,p.height>d.height&&(p.top=d.top,p.height=d.height,c="auto"),{left:p.left,top:p.top,width:p.width,overflowY:c,maxWidth:d.width}}let CloseIcon=()=>p("svg",{viewBox:"0 0 24 24",role:"presentation",style:{width:"1.2rem",height:"1.2rem"},children:p("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(t,e){let{style:o}=e,i,r=[...(t=t||{}).className?t.className.split(" "):[],...(e.className?Array.isArray(e.className)?e.className:e.className.split(" "):[]).filter(t=>!!t)],a=r.length?r.join(" "):void 0,n={...t.style,...o};return{...t,className:a,style:n,...e.attrs}}let usePopup=t=>{let[e,i]=o([]),r=a(e);r.current=e;let[n,d]=o([]),_=a(n);_.current=n;let[h,$]=o(),m=t=>{void 0===t.id&&(t.id="popup"+Math.round(1e6*Math.random()));let e=t;i(o=>[...o.filter(({id:e})=>e!==t.id),e])},g=async t=>{if("string"!=typeof t&&(t="last"),"all"===t){i([]);return}if(!r.current.length)return;"last"===t&&(t=r.current[r.current.length-1].id);let e=r.current.find(e=>e.id===t);e&&(s(`[data-id=${t}]`).addClass("not-mounted"),setTimeout(()=>{e&&"function"==typeof e.onClose&&e.onClose(),i(e=>e.filter(e=>e.id!==t))},300))},f=t=>{d([..._.current,{...t,id:"a"+Math.round(1e9*Math.random())}])},v=t=>{let e=_.current,o=e.find(e=>e.id===t);if(o&&!1!==o.onClose)d(e.filter((e,o)=>e.id!==t)),"function"==typeof o.onClose&&o.onClose()},b=t=>Alert(t),C=t=>$(t),k=()=>$(void 0),y=t=>{let{title:e,subtitle:o,text:i,submitText:r="Yes",canselText:a="No",onSubmit:n,onCansel:l=()=>{},setAttrs:d=()=>({})}=t,s={position:"center",setAttrs(t){let e=d(t);return"modal"===t?AddToAttrs(e,{className:"aio-popup-confirm"}):e},header:{title:e,subtitle:o},body:()=>i,footer:()=>u(c,{children:[p("button",{type:"button",onClick(){l(),g()},children:a}),p("button",{type:"button",className:"active",async onClick(){if(n)!1!==await n()&&g()},children:r})]})};m(s)},L=t=>{let{title:e,subtitle:o,text:i,submitText:r="Submit",canselText:a="close",onSubmit:n,onCansel:l=()=>{},setAttrs:d=()=>({})}=t,s={position:"center",setAttrs(t){let e=d(t);return"modal"===t?AddToAttrs(e,{className:"aio-popup-prompt"}):e},state:{temp:""},header:{title:e,subtitle:o},body:({state:t,setState:e})=>p("textarea",{placeholder:i,value:t.temp,onChange(t){e&&e({temp:t.target.value})}}),footer:({state:t,setState:e})=>u(c,{children:[p("button",{type:"button",onClick(){l(),g()},children:a}),p("button",{type:"button",className:"active",async onClick(){if(n)!1!==await n(t.temp)?g():e({temp:""})},disabled:!t.temp,children:r})]})};m(s)},M=()=>({rtl:!!t&&!!t.rtl,snackebarItems:_.current,removeSnackebar:v,removeModal:g}),S=()=>u(CTX.Provider,{value:M(),children:[r.current.map((t,e)=>p(Popup,{modal:t,isLast:e===r.current.length-1},t.id)),n.map((t,e)=>p(SnackebarItem,{item:t,index:e},t.id)),!!h&&p(Highlight,{highlight:h})]}),w=()=>l.createPortal(S(),document.body);return{addAlert:b,addSnackebar:f,removeModal:g,addModal:m,getModals:()=>r.current,addHighlight:C,removeHighlight:k,render:S,addConfirm:y,addPrompt:L,portal:w}};export default usePopup;let POPUPCTX=i({}),Popup=({modal:i,isLast:n})=>{let l=r(CTX),{setAttrs:d=()=>({}),id:c,position:_="fullscreen",getTarget:h}=i,[$]=o({dom:t(),backdropDom:t(),dui:void 0}),[m,g]=o({}),[f,v]=o(i.state),b=d("modal")||{},C=a(!1);function k(t){if(!$.dui)return;let e=s(t.target);"popover"===_&&e.attr("data-id")!==$.dui&&!e.parents(`[data-id=${$.dui}]`).length&&l.removeModal()}function y(){let t={...m,...b.style},e="ontouchstart"in document.documentElement?"onTouchStart":"onMouseDown";return{...b,ref:$.dom,"data-id":i.id,tabIndex:0,onKeyDown:M,[e]:w,className:T(),style:{...t}}}function L(){if(!h)return{};let t=h();if(!t||!t.length)return{};let e={modal:s($.dom.current),target:t,fitHorizontal:i.fitHorizontal,limitTo:i.limitTo,attrs:b,rtl:l.rtl};return{...Align(e),position:"absolute"}}function M(t){if(n)27===t.keyCode&&l.removeModal()}function S(){}function w(t){s(window).unbind("mouseup",S),s(window).bind("mouseup",S)}function T(){let t="aio-popup";return t+=l.rtl?" rtl":" ltr",C&&(t+=" not-mounted"),b.className&&(t+=" "+b.className),t}e(()=>()=>{s(window).unbind("click",k)}),e(()=>{let t="popover"===_?L():{};if(console.log("updatedStyle.top",t.top),g(t),h){$.dui="a"+Math.round(1e7*Math.random());h().attr("data-id",$.dui)}setTimeout(()=>{let t=s($.dom.current);t.removeClass("not-mounted"),s($.backdropDom.current).removeClass("not-mounted"),t.focus()},0),s(window).unbind("click",k),s(window).bind("click",k)},[]);let x=()=>({mainContext:l,modal:i,isLast:n,state:f,setState:v,onKeyDown:M});return p(POPUPCTX.Provider,{value:x(),children:p(ModalBackdrop,{content:u("div",{...y(),children:[p(ModalHeader,{}),p(ModalBody,{}),p(ModalFooter,{})]}),firstMount:!!C,ref:$.backdropDom})})},ModalBackdrop=({content:t,firstMount:e,ref:i})=>{let{mainContext:a,modal:n,onKeyDown:l}=r(POPUPCTX),{setAttrs:d=()=>({}),id:c,position:u="fullscreen"}=n,[_]=o(d("backdrop")||{});function h(t){if(t.target===t.currentTarget){t.stopPropagation();s(t.target).hasClass("aio-popup-backdrop")&&a.removeModal()}}function $(){let t="aio-popup-backdrop";return t+=` aio-popup-position-${u}`,t+=a.rtl?" rtl":" ltr",e&&(t+=" not-mounted"),AddToAttrs(_,{className:t,attrs:{ref:i,onKeyDown:l,tabIndex:0,"data-id":c,onClick:_.onClick?_.onClick:h}})}return p("div",{...$(),children:t})},ModalHeader=()=>{let{mainContext:t,modal:e,state:o,setState:i}=r(POPUPCTX);if(!e.header)return null;let{setAttrs:a=()=>({})}=e,n=a("header")||{};return"function"==typeof e.header?e.header({removeModal:t.removeModal,state:o,setState:i}):"object"!=typeof e.header?null:u("div",{...AddToAttrs(n,{className:"aio-popup-header"}),children:[p(ModalHeaderElement,{type:"before"},"before"),p(ModalHeaderElement,{type:"title"},"title"),p(ModalHeaderElement,{type:"after"},"after"),p(ModalClose,{})]})},ModalHeaderElement=({type:t})=>{let{modal:e}=r(POPUPCTX),{header:o}=e;return"function"!=typeof o&&o&&o[t]?p("div",{className:`aio-popup-header-${t}`,"data-subtitle":"title"===t?o.subtitle:void 0,children:o[t]}):null},ModalClose=()=>{let{modal:t,state:e,setState:o,mainContext:i}=r(POPUPCTX),{header:a}=t;return"function"!=typeof a&&a&&!1!==a.onClose?p("div",{className:"aio-popup-header-close",onClick(r){r.stopPropagation(),r.preventDefault(),"function"==typeof a.onClose?a.onClose({state:e,setState:o}):i.removeModal(t.id)},children:p(CloseIcon,{})}):null},ModalBody=()=>{let{mainContext:t,state:e,setState:o,modal:i}=r(POPUPCTX),{body:a=()=>null,setAttrs:n=()=>({})}=i,l=n("body")||{},d={removeModal:t.removeModal,state:e,setState:o},s=a(d);return s&&null!==s?p("div",{...AddToAttrs(l,{className:"aio-popup-body aio-popup-scroll"}),children:s}):null},ModalFooter=()=>{let{mainContext:t,modal:e,state:o,setState:i}=r(POPUPCTX),{setAttrs:a=()=>({}),footer:n}=e;if(!n)return null;let l=a("footer")||{},d=AddToAttrs(l,{className:"aio-popup-footer"});return p("div",{...d,children:n({state:o,setState:i,removeModal:t.removeModal})})},SBCTX=i({}),SnackebarItem=t=>{let i=r(CTX),{item:a}=t,{time:n=8,id:l,align:d=["right","top"]}=a;"top"!==d[1]&&"bottom"!==d[1]&&(d[1]="top"),"left"!==d[0]&&"right"!==d[0]&&"center"!==d[0]&&(d[0]="right");let[s,c]=o(!1);function u(){c(!1),setTimeout(()=>i.removeSnackebar(l),200)}e(()=>{setTimeout(()=>c(!0),0),setTimeout(()=>u(),1e3*n)},[]);let _=t=>"error"===t||"warning"===t||"info"===t?p(InfoSvg,{}):p(SuccessSvg,{}),h=()=>({mainContext:i,remove:u,item:{...t.item,time:n,align:d},index:t.index,mounted:s,getSvg:_});return p(SBCTX.Provider,{value:h(),children:p(SnackebarContainer,{})})},SnackebarContainer=()=>{let{mainContext:t,mounted:e,index:o,item:i,remove:a}=r(SBCTX),{rtl:n}=t,{onClose:l,align:d=["right","top"]}=i;function c(t){let e=s(".aio-popup-snackebar-item-container"),o={top:12,bottom:12};for(let i=0;i<t;i++){let r=e.eq(i),a=r.height()+6,n=r.attr("data-vertical-align");o[n]+=a}return{["top"===d[1]?"top":"bottom"]:o[d[1]]}}let u="aio-popup-snackebar-item-container";u+=` aio-popup-snackebar-item-container-horizontal-align-${d[0]}`,e&&(u+=" mounted"),n&&(u+=" rtl");let _=c(o),h={"data-vertical-align":d[1],className:u,style:_,onClick:!1===l?void 0:()=>a()};return p("div",{...h,children:p(SnackebarCard,{})})},SnackebarCard=()=>{let{item:t}=r(SBCTX),{type:e,attrs:o={}}=t,i="aio-popup-snackebar-item";return i+=` aio-popup-snackebar-item-${e}`,o.className&&(i+=` ${o.className}`),u("div",{...{...o,className:i,style:o.style},children:[p(SnackebarIcon,{}),p(SnackebarText,{}),p(SnackebarAction,{}),p(SnackebarBar,{})]})},SnackebarIcon=()=>{let{getSvg:t,item:e}=r(SBCTX);return p("div",{className:"aio-popup-snackebar-item-icon",children:e.icon?e.icon:t(e.type)})},SnackebarText=()=>{let{item:t}=r(SBCTX);return u("div",{className:"aio-popup-snackebar-item-text",children:[p("div",{className:"aio-popup-snackebar-item-uptext",children:t.text}),!!t.subtext&&p("div",{className:"aio-popup-snackebar-item-subtext",children:t.subtext})]})},SnackebarAction=()=>{let{item:t,remove:e}=r(SBCTX),{action:o}=t;return o&&o.text?p("button",{className:"aio-popup-snackebar-item-action",onClick(t){t.stopPropagation(),o&&o.onClick(),e()},children:o.text}):null},SnackebarBar=()=>{let{item:t}=r(SBCTX);return p("div",{className:"aio-popup-snackebar-bar",style:{transition:`${t.time||8}s linear`}})};export function Alert(t){let{icon:e,type:o="",text:i="",subtext:r="",time:a=10,className:l,closeText:d="Close",onClose:p}=t,c={id:"",time:0,getId:()=>"aa"+Math.round(1e8*Math.random()),getBarRender:()=>`<div class='aio-popup-time-bar' style="width:${c.time}%;"></div>`,updateBarRender(){s(`.aio-popup-alert-container.${c.id} .aio-popup-time`).html(c.getBarRender())},getRender:()=>`
2
- <div class='aio-popup-alert-container not-mounted ${c.id} aio-popup-alert-container-center${l?` ${l}`:""}'>
3
- <div class='aio-popup-alert aio-popup-alert-${o}'>
4
- <div class='aio-popup-alert-header'>${c.getIcon()}</div>
5
- <div class='aio-popup-alert-body aio-popup-scroll'>
6
- <div class='aio-popup-alert-text'>${n.renderToStaticMarkup(i)}</div>
7
- <div class='aio-popup-alert-subtext'>${r}</div>
8
- </div>
9
- <div class='aio-popup-alert-footer'>
10
- <button class='aio-popup-alert-close ${c.id}'>${d}</button>
11
- </div>
12
- <div class='aio-popup-time'></div>
13
- </div>
14
- </div>
15
- `,close(){c.toggleClass(!1),setTimeout(()=>{"function"==typeof p&&p(),!1!==p&&s("."+c.id).remove()},200)},getIcon:()=>!1===e?"":e||({error:'<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z"></path></svg>',warning:'<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M12,2L1,21H23M12,6L19.53,19H4.47M11,10V14H13V10M11,16V18H13V16"></path></svg>',info:'<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z"></path></svg>',success:'<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M12 20C7.59 20 4 16.41 4 12S7.59 4 12 4 20 7.59 20 12 16.41 20 12 20M16.59 7.58L10 14.17L7.41 11.59L6 13L10 17L18 9L16.59 7.58Z"></path></svg>'})[o]||"",startTimer(){setTimeout(()=>{if(c.time>=100){c.time=100,c.close();return}c.time+=2,c.updateBarRender(),c.startTimer()},a/50*1e3)},toggleClass(t){let e=s(`.${c.id}`);t?setTimeout(()=>e.removeClass("not-mounted"),0):e.addClass("not-mounted")},render(){s("body").append(c.getRender()),s("button."+c.id).off("click",c.close),s("button."+c.id).on("click",c.close),c.toggleClass(!0)}};c.id=c.getId(),c.render(),a&&c.startTimer()}let Highlight=({highlight:t})=>{let[i,r]=o({Left:0,Top:0,Width:0,Height:0,TopSpace:0,BottomSpace:0}),n=a(i);function l(t){return p("svg",{version:"1.1",id:"Layer_1",xmlns:"http://www.w3.org/2000/svg",x:"0px",y:"0px",viewBox:"0 0 512 512",...t,children:u("g",{children:[p("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"}),p("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 s(t,e,o){return p("div",{className:"aio-popup-highlight-arrow",children:l({width:24,height:24,style:{position:"absolute",height:24,width:24,left:e+o/2-12},className:`aio-popup-highlight-arrow-${t}`})})}function _(e){if(!t.html)return"";let o,i=t.html||"",r=p("div",{className:"aio-popup-highlight-space"}),a=p("div",{className:"aio-popup-highlight-html",children:i}),l=s(e,n.current.Left,n.current.Width);return o="top"===e?u(c,{children:[r,a,l]}):u(c,{children:[l,a,r]}),p("div",{className:"aio-popup-highlight-html-container",children:o})}function h(){!t.mouseAccess&&t.onClick&&t.onClick()}function $(t){let e="",o=0,i="aio-popup-highlight-mask",r=n.current;return"top"===t?(o=r.Top,r.TopSpace>r.BottomSpace&&(e=_("top"))):"bottom"===t?(i+=" aio-popup-highlight-mask-flex",r.TopSpace<=r.BottomSpace&&(e=_("bottom"))):"left"===t?o=r.Left:i+=" aio-popup-highlight-mask-flex",p("div",{className:i,style:{["top"===t||"bottom"===t?"height":"width"]:o},onClick:()=>h(),children:e})}function m(){return p("div",{style:{width:i.Width},className:"aio-popup-highlight-focus-container",onClick:h,children:p("div",{className:"aio-popup-highlight-focus"})})}function g(){return u("div",{className:"aio-popup-highlight-main",style:{height:i.Height},children:[$("left"),m(),$("right")]})}function f(){return{pointerEvents:t.mouseAccess?"none":"all"}}n.current=i,e(()=>{setTimeout(()=>{try{let{dom:e,duration:o=1200}=t;e[0].scrollIntoView();let i=getHLLimit(t),a=getEasing(t),l={...i,targets:[{...n.current}],duration:o,update(t){let{animatables:e}=t;r({...e[0].target})}};a&&(l.easing=a),d(l)}catch{alert("aio-highlighter error => connot find dom")}},0)});let v=AddToAttrs(t.attrs,{className:"aio-popup-highlight",style:f()});return u("div",{...v,children:[$("top"),g(),$("bottom")]})};function getHLLimit(t){let{padding:e=6,dom:o}=t,i=o.offset(),r=i.left-window.pageXOffset,a=i.top-window.pageYOffset,n=window.innerHeight,l=o.outerWidth(),d=o.outerHeight();return{Left:r-1*e,Top:a-1*e,Width:l+2*e,Height:d+2*e,TopSpace:a,BottomSpace:n-(a+d)}}function getEasing(t){let{easing:e}=t;var o=["linear","easeInQuad","easeInSine","easeInCirc","easeInBack","easeOutQuad","easeOutSine","easeOutCirc","easeInOutQuad","easeInOutSine","easeInOutBack","easeOutBounce"];return"number"==typeof e?o[e]||o[0]:e}let InfoSvg=()=>p("svg",{viewBox:"0 0 24 24",role:"presentation",style:{width:"1.2rem",height:"1.2rem"},children:p("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"}})}),SuccessSvg=()=>p("svg",{viewBox:"0 0 24 24",role:"presentation",style:{width:"1.2rem",height:"1.2rem"},children:p("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"}})});function getBound(t){try{let e=t.getBoundingClientRect();return{width:e.width,height:e.height,left:e.left,top:e.top,bottom:e.bottom,right:e.right}}catch{return{width:0,height:0,left:0,top:0,bottom:0,right:0}}}
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
11
+ /* eslint-disable @typescript-eslint/no-unnecessary-condition */
12
+ import { createRef, useEffect, useState, createContext, useContext, useRef } from 'react';
13
+ import * as ReactDOMServer from 'react-dom/server';
14
+ import ReactDOM from 'react-dom';
15
+ import anime from "animejs/lib/anime.es.js";
16
+ import $ from 'jquery';
17
+ import './index.css';
18
+ const CTX = createContext({});
19
+ function Align(p) {
20
+ let { modal, target, fitHorizontal, rtl, limitTo } = p;
21
+ const bodyWidth = window.innerWidth, bodyHeight = window.innerHeight;
22
+ let pageLimit = { left: 0, top: 0, bottom: bodyHeight, right: bodyWidth, width: bodyWidth, height: bodyHeight };
23
+ let targetLimit = getBound(target[0]);
24
+ let domLimit = getBound(modal[0]);
25
+ targetLimit = Object.assign({}, targetLimit);
26
+ domLimit = Object.assign({}, domLimit);
27
+ let overflowY;
28
+ domLimit.top = targetLimit.bottom;
29
+ domLimit.bottom = domLimit.top + domLimit.height;
30
+ if (fitHorizontal) {
31
+ domLimit.width = targetLimit.width;
32
+ domLimit.left = targetLimit.left;
33
+ domLimit.right = targetLimit.left + targetLimit.width;
34
+ }
35
+ else {
36
+ if (limitTo) {
37
+ let elem = modal.parents(limitTo);
38
+ if (elem.length) {
39
+ pageLimit = getBound(elem[0]);
40
+ }
41
+ }
42
+ //اگر راست به چپ باید باشد
43
+ if (rtl) {
44
+ //راست المان را با راست هدف ست کن
45
+ domLimit.right = targetLimit.right;
46
+ //چپ المان را بروز رسانی کن
47
+ domLimit.left = domLimit.right - domLimit.width;
48
+ //اگر المان از سمت چپ از صفحه بیرون زد سمت چپ المان را با سمت چپ صفحه ست کن
49
+ if (domLimit.left < pageLimit.left) {
50
+ domLimit.left = pageLimit.left;
51
+ }
52
+ }
53
+ else {
54
+ //چپ المان را با چپ هدف ست کن
55
+ domLimit.left = targetLimit.left;
56
+ //راست المان را بروز رسانی کن
57
+ domLimit.right = domLimit.left + domLimit.width;
58
+ //اگر المان از سمت راست صفحه بیرون زد سمت چپ المان را با پهنای المان ست کن
59
+ if (domLimit.right > pageLimit.right) {
60
+ domLimit.left = pageLimit.right - domLimit.width;
61
+ }
62
+ }
63
+ }
64
+ //اگر المان از سمت پایین صفحه بیرون زد
65
+ if (domLimit.bottom > pageLimit.bottom) {
66
+ if (domLimit.height > targetLimit.top - pageLimit.top) {
67
+ domLimit.top = pageLimit.bottom - domLimit.height;
68
+ }
69
+ else {
70
+ domLimit.top = targetLimit.top - domLimit.height;
71
+ }
72
+ }
73
+ else {
74
+ domLimit.top = targetLimit.bottom;
75
+ }
76
+ if (domLimit.height > pageLimit.height) {
77
+ domLimit.top = pageLimit.top;
78
+ domLimit.height = pageLimit.height;
79
+ overflowY = 'auto';
80
+ }
81
+ return { left: domLimit.left, top: domLimit.top, width: domLimit.width, overflowY, maxWidth: pageLimit.width };
82
+ }
83
+ const CloseIcon = () => {
84
+ return (_jsx("svg", { viewBox: "0 0 24 24", role: "presentation", style: { width: '1.2rem', height: '1.2rem' }, children: _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' } }) }));
85
+ };
86
+ function AddToAttrs(attrs, p) {
87
+ attrs = attrs || {};
88
+ let { style } = p;
89
+ let attrClassName = attrs.className ? attrs.className.split(' ') : [];
90
+ let className = p.className ? (Array.isArray(p.className) ? p.className : p.className.split(' ')) : [];
91
+ let classNames = [...attrClassName, ...className.filter((o) => !!o)];
92
+ let newClassName = classNames.length ? classNames.join(' ') : undefined;
93
+ let newStyle = Object.assign(Object.assign({}, attrs.style), style);
94
+ return Object.assign(Object.assign(Object.assign({}, attrs), { className: newClassName, style: newStyle }), p.attrs);
95
+ }
96
+ const usePopup = (props) => {
97
+ let [modals, setModals] = useState([]);
98
+ const promptTexts = useRef({});
99
+ let modalsRef = useRef(modals);
100
+ modalsRef.current = modals;
101
+ const getModals = () => modalsRef.current;
102
+ const [snackebarItems, setSnackebarItems] = useState([]);
103
+ const snackebarItemsRef = useRef(snackebarItems);
104
+ snackebarItemsRef.current = snackebarItems;
105
+ const [highlight, setHighlight] = useState();
106
+ const addModal = (o) => {
107
+ if (o.id === undefined) {
108
+ o.id = 'popup' + Math.round(Math.random() * 1000000);
109
+ }
110
+ let newModal = o;
111
+ setModals(prevModals => {
112
+ let newModals = prevModals.filter(({ id }) => id !== o.id);
113
+ return [...newModals, newModal];
114
+ });
115
+ };
116
+ const removeModal = (arg) => __awaiter(void 0, void 0, void 0, function* () {
117
+ if (typeof arg !== 'string') {
118
+ arg = 'last';
119
+ }
120
+ if (arg === 'all') {
121
+ setModals([]);
122
+ return;
123
+ }
124
+ if (!modalsRef.current.length) {
125
+ return;
126
+ }
127
+ if (arg === 'last') {
128
+ arg = modalsRef.current[modalsRef.current.length - 1].id;
129
+ }
130
+ let modal = modalsRef.current.find((o) => o.id === arg);
131
+ if (!modal) {
132
+ return;
133
+ }
134
+ $(`[data-id=${arg}]`).addClass('not-mounted');
135
+ setTimeout(() => {
136
+ if (modal && typeof modal.onClose === 'function') {
137
+ modal.onClose();
138
+ }
139
+ setModals(prevModals => prevModals.filter((o) => o.id !== arg));
140
+ }, 300);
141
+ });
142
+ const addSnackebar = (item) => {
143
+ let items = snackebarItemsRef.current;
144
+ let newItems = [...items, Object.assign(Object.assign({}, item), { id: 'a' + Math.round(Math.random() * 1000000000) })];
145
+ setSnackebarItems(newItems);
146
+ };
147
+ const removeSnackebar = (id) => {
148
+ const items = snackebarItemsRef.current;
149
+ const item = items.find((o) => o.id === id);
150
+ if (!item || item.onClose === false) {
151
+ return;
152
+ }
153
+ let newItems = items.filter((o, i) => o.id !== id);
154
+ setSnackebarItems(newItems);
155
+ if (typeof item.onClose === 'function') {
156
+ item.onClose();
157
+ }
158
+ };
159
+ const addAlert = (obj) => Alert(obj);
160
+ const addHighlight = (highlight) => setHighlight(highlight);
161
+ const removeHighlight = () => setHighlight(undefined);
162
+ const addConfirm = (obj) => {
163
+ let { title, subtitle, submitText = 'Yes', canselText = 'No', onSubmit, onCansel = () => { }, setAttrs = () => { return {}; } } = obj;
164
+ let config = {
165
+ position: 'center',
166
+ setAttrs: (key) => {
167
+ let attrs = setAttrs(key);
168
+ if (key === 'modal') {
169
+ return AddToAttrs(attrs, { className: 'aio-popup-confirm' });
170
+ }
171
+ return attrs;
172
+ },
173
+ header: { title, subtitle },
174
+ body: _jsx(_Fragment, { children: "text" }),
175
+ footer: (_jsxs(_Fragment, { children: [_jsx("button", { type: 'button', onClick: () => { onCansel(); removeModal(); }, children: canselText }), _jsx("button", { type: 'button', className: 'active', onClick: () => __awaiter(void 0, void 0, void 0, function* () {
176
+ if (!onSubmit) {
177
+ return;
178
+ }
179
+ let res = yield onSubmit();
180
+ if (res !== false) {
181
+ removeModal();
182
+ }
183
+ }), children: submitText })] }))
184
+ };
185
+ addModal(config);
186
+ };
187
+ const addPrompt = (obj) => {
188
+ const id = 'a' + (Math.round(Math.random() * 100000));
189
+ let { title, subtitle, submitText = 'Submit', canselText = 'close', onSubmit, onCansel = () => { }, setAttrs = () => { return {}; } } = obj;
190
+ let config = {
191
+ position: 'center',
192
+ setAttrs: (key) => {
193
+ let attrs = setAttrs(key);
194
+ if (key === 'modal') {
195
+ return AddToAttrs(attrs, { className: 'aio-popup-prompt' });
196
+ }
197
+ return attrs;
198
+ },
199
+ header: { title, subtitle },
200
+ body: _jsx(Prompt, { change: (value) => promptTexts.current = Object.assign(Object.assign({}, promptTexts.current), { [id]: value }) }),
201
+ footer: (_jsxs(_Fragment, { children: [_jsx("button", { type: 'button', onClick: () => { onCansel(); removeModal(); }, children: canselText }), _jsx("button", { type: 'button', className: 'active', onClick: () => __awaiter(void 0, void 0, void 0, function* () {
202
+ if (!onSubmit) {
203
+ return;
204
+ }
205
+ const value = promptTexts.current[id];
206
+ let res = yield onSubmit(value);
207
+ if (res !== false) {
208
+ removeModal();
209
+ }
210
+ else {
211
+ const newPromptTexts = {};
212
+ for (let prop in promptTexts.current) {
213
+ if (prop !== id) {
214
+ newPromptTexts[prop] = promptTexts.current[prop];
215
+ }
216
+ }
217
+ promptTexts.current = newPromptTexts;
218
+ }
219
+ }), disabled: !promptTexts.current[id], children: submitText })] }))
220
+ };
221
+ addModal(config);
222
+ };
223
+ const getContext = () => {
224
+ return {
225
+ rtl: !!props && !!props.rtl,
226
+ snackebarItems: snackebarItemsRef.current,
227
+ removeSnackebar, removeModal
228
+ };
229
+ };
230
+ const render = (caller) => {
231
+ return (_jsxs(CTX.Provider, { value: getContext(), children: [modalsRef.current.map((modal, i) => {
232
+ return (_jsx(Popup, { modal: modal, isLast: i === modalsRef.current.length - 1, renderCaller: caller }, modal.id));
233
+ }), snackebarItems.map((item, i) => _jsx(SnackebarItem, { item: item, index: i }, item.id)), !!highlight && _jsx(Highlight, { highlight: highlight })] }));
234
+ };
235
+ const portal = () => ReactDOM.createPortal(render(), document.body);
236
+ return { addAlert, addSnackebar, removeModal, addModal, getModals, addHighlight, removeHighlight, render, addConfirm, addPrompt, portal };
237
+ };
238
+ export default usePopup;
239
+ const Prompt = ({ change }) => {
240
+ const [text, setText] = useState('');
241
+ return (_jsx("textarea", { placeholder: text, value: text, onChange: (e) => { const value = e.target.value; setText(value); change(value); } }));
242
+ };
243
+ const POPUPCTX = createContext({});
244
+ const Popup = ({ modal, isLast, renderCaller }) => {
245
+ const mainContext = useContext(CTX);
246
+ let { setAttrs = () => { return {}; }, id, position = 'fullscreen', getTarget } = modal;
247
+ let [temp] = useState({ dom: createRef(), backdropDom: createRef(), dui: undefined });
248
+ let [popoverStyle, setPopoverStyle] = useState({});
249
+ let modalMouseDown = useRef(false);
250
+ //bar taraf kardane moshkele mozakhrafe click rooye backdrop ke az har ja mouse ro roosh vel mikoni modal baste mishe
251
+ const isModalMouseDown = () => modalMouseDown.current;
252
+ let [state, setState] = useState(modal.state);
253
+ let attrs = setAttrs('modal') || {};
254
+ const firstMount = useRef(false);
255
+ useEffect(() => () => { $(window).unbind('click', handleBackClick); });
256
+ useEffect(() => {
257
+ if (position === 'popover') {
258
+ setPopoverStyle(getPopoverStyle());
259
+ }
260
+ if (getTarget) {
261
+ temp.dui = 'a' + (Math.round(Math.random() * 10000000));
262
+ let target = getTarget();
263
+ target.attr('data-id', temp.dui);
264
+ }
265
+ setTimeout(() => {
266
+ let popup = $(temp.dom.current);
267
+ popup.removeClass('not-mounted');
268
+ $(temp.backdropDom.current).removeClass('not-mounted');
269
+ popup.focus();
270
+ }, 0);
271
+ $(window).unbind('click', handleBackClick);
272
+ $(window).bind('click', handleBackClick);
273
+ }, []);
274
+ function handleBackClick(e) {
275
+ //در مود پاپاور اگر هر جایی غیر از اینپوت و پاپاور کلیک شد پاپاپ رو ببند
276
+ if (!temp.dui) {
277
+ return;
278
+ }
279
+ let target = $(e.target);
280
+ if (position !== 'popover' || target.attr('data-id') === temp.dui || target.parents(`[data-id=${temp.dui}]`).length) {
281
+ return;
282
+ }
283
+ mainContext.removeModal();
284
+ }
285
+ function getModalProps() {
286
+ let style = Object.assign(Object.assign({}, popoverStyle), attrs.style);
287
+ let ev = "ontouchstart" in document.documentElement ? 'onTouchStart' : 'onMouseDown';
288
+ return Object.assign(Object.assign({}, attrs), { ref: temp.dom, "data-id": modal.id, tabIndex: 0, onKeyDown, [ev]: mouseDown, className: getClassName(), style: Object.assign({}, style), onClick: (e) => { e.stopPropagation(); } });
289
+ }
290
+ function getPopoverStyle() {
291
+ if (!getTarget) {
292
+ return {};
293
+ }
294
+ let target = getTarget();
295
+ if (!target || !target.length) {
296
+ return {};
297
+ }
298
+ let p = { modal: $(temp.dom.current), target, fitHorizontal: modal.fitHorizontal, limitTo: modal.limitTo, attrs, rtl: mainContext.rtl };
299
+ let style = Align(p);
300
+ let res = Object.assign(Object.assign({}, style), { position: 'absolute' });
301
+ return res;
302
+ }
303
+ function onKeyDown(e) {
304
+ if (!isLast) {
305
+ return;
306
+ }
307
+ let code = e.keyCode;
308
+ if (code === 27) {
309
+ mainContext.removeModal();
310
+ }
311
+ }
312
+ function mouseUp() {
313
+ setTimeout(() => modalMouseDown.current = false, 0);
314
+ }
315
+ function mouseDown(e) {
316
+ modalMouseDown.current = true;
317
+ $(window).unbind('mouseup', mouseUp);
318
+ $(window).bind('mouseup', mouseUp);
319
+ }
320
+ function getClassName() {
321
+ let className = 'aio-popup';
322
+ className += mainContext.rtl ? ' rtl' : ' ltr';
323
+ if (firstMount) {
324
+ className += ' not-mounted';
325
+ }
326
+ if (attrs.className) {
327
+ className += ' ' + attrs.className;
328
+ }
329
+ return className;
330
+ }
331
+ const getContext = () => ({ modal, isLast, state, setState, onKeyDown });
332
+ return (_jsx(POPUPCTX.Provider, { value: getContext(), children: _jsx(ModalBackdrop, { firstMount: !!firstMount, backdropDom: temp.backdropDom, isModalMouseDown: isModalMouseDown, children: _jsxs("div", Object.assign({}, getModalProps(), { children: [_jsx(ModalHeader, {}), _jsx(ModalBody, {}, modal.id), _jsx(ModalFooter, {})] }), modal.id) }, modal.id) }));
333
+ };
334
+ const ModalBackdrop = ({ children, firstMount, backdropDom, isModalMouseDown }) => {
335
+ const { removeModal, rtl } = useContext(CTX);
336
+ let { modal, onKeyDown } = useContext(POPUPCTX);
337
+ let { setAttrs = () => { return {}; }, id, position = 'fullscreen' } = modal;
338
+ const [attrs] = useState(setAttrs('backdrop') || {});
339
+ function backClick(e) {
340
+ if (isModalMouseDown()) {
341
+ return;
342
+ }
343
+ if (e.target !== e.currentTarget) {
344
+ return;
345
+ }
346
+ let target = $(e.target);
347
+ if (!target.hasClass('aio-popup-backdrop')) {
348
+ return;
349
+ }
350
+ removeModal();
351
+ }
352
+ function getProps() {
353
+ let className = 'aio-popup-backdrop';
354
+ className += ` aio-popup-position-${position}`;
355
+ className += rtl ? ' rtl' : ' ltr';
356
+ if (firstMount) {
357
+ className += ' not-mounted';
358
+ }
359
+ return AddToAttrs(attrs, { className, attrs: { ref: backdropDom, onKeyDown, tabIndex: 0, ['data-id']: id, onClick: attrs.onClick ? attrs.onClick : backClick } });
360
+ }
361
+ return _jsx("div", Object.assign({}, getProps(), { children: children }));
362
+ };
363
+ const ModalHeader = () => {
364
+ const { removeModal } = useContext(CTX);
365
+ let { modal, state, setState } = useContext(POPUPCTX);
366
+ if (!modal.header) {
367
+ return null;
368
+ }
369
+ let { setAttrs = () => { return {}; } } = modal;
370
+ let attrs = setAttrs('header') || {};
371
+ if (typeof modal.header === 'function') {
372
+ return modal.header({ removeModal: removeModal, state, setState });
373
+ }
374
+ if (typeof modal.header !== 'object') {
375
+ return null;
376
+ }
377
+ return (_jsxs("div", Object.assign({}, AddToAttrs(attrs, { className: 'aio-popup-header' }), { children: [_jsx(ModalHeaderElement, { type: 'before' }, 'before'), _jsx(ModalHeaderElement, { type: 'title' }, 'title'), _jsx(ModalHeaderElement, { type: 'after' }, 'after'), _jsx(ModalClose, {})] })));
378
+ };
379
+ const ModalHeaderElement = ({ type }) => {
380
+ let { modal } = useContext(POPUPCTX), { header } = modal;
381
+ if (typeof header === 'function' || !header) {
382
+ return null;
383
+ }
384
+ if (!header[type]) {
385
+ return null;
386
+ }
387
+ return _jsx("div", { className: `aio-popup-header-${type}`, "data-subtitle": type === 'title' ? header.subtitle : undefined, children: header[type] });
388
+ };
389
+ const ModalClose = () => {
390
+ const { removeModal } = useContext(CTX);
391
+ let { modal, state, setState } = useContext(POPUPCTX), { header } = modal;
392
+ if (typeof header === 'function' || !header) {
393
+ return null;
394
+ }
395
+ if (header.onClose === false) {
396
+ return null;
397
+ }
398
+ return _jsx("div", { className: `aio-popup-header-close`, onClick: (e) => {
399
+ e.stopPropagation();
400
+ e.preventDefault();
401
+ if (typeof header.onClose === 'function') {
402
+ header.onClose({ state, setState });
403
+ }
404
+ else {
405
+ removeModal(modal.id);
406
+ }
407
+ }, children: _jsx(CloseIcon, {}) });
408
+ };
409
+ const ModalBody = () => {
410
+ const { modal } = useContext(POPUPCTX);
411
+ let { body, setAttrs = () => { return {}; } } = modal;
412
+ let attrs = setAttrs('body') || {};
413
+ if (!body || body === null) {
414
+ return null;
415
+ }
416
+ return (_jsx("div", Object.assign({}, AddToAttrs(attrs, { className: 'aio-popup-body aio-popup-scroll' }), { children: body })));
417
+ };
418
+ const ModalFooter = () => {
419
+ const { modal } = useContext(POPUPCTX);
420
+ let { setAttrs = () => { return {}; }, footer } = modal;
421
+ if (!footer) {
422
+ return null;
423
+ }
424
+ let Attrs = setAttrs('footer') || {};
425
+ const attrs = AddToAttrs(Attrs, { className: 'aio-popup-footer' });
426
+ return _jsx("div", Object.assign({}, attrs, { children: footer }));
427
+ };
428
+ const SBCTX = createContext({});
429
+ const SnackebarItem = (props) => {
430
+ const mainContext = useContext(CTX);
431
+ let { item } = props;
432
+ let { time = 8, id, align = ['right', 'top'] } = item;
433
+ if (align[1] !== 'top' && align[1] !== 'bottom') {
434
+ align[1] = 'top';
435
+ }
436
+ if (align[0] !== 'left' && align[0] !== 'right' && align[0] !== 'center') {
437
+ align[0] = 'right';
438
+ }
439
+ let [mounted, setMounted] = useState(false);
440
+ useEffect(() => {
441
+ setTimeout(() => setMounted(true), 0);
442
+ setTimeout(() => remove(), time * 1000);
443
+ }, []);
444
+ function remove() {
445
+ setMounted(false);
446
+ setTimeout(() => mainContext.removeSnackebar(id), 200);
447
+ }
448
+ const getSvg = (type) => { return type === 'error' || type === 'warning' || type === 'info' ? _jsx(InfoSvg, {}) : _jsx(SuccessSvg, {}); };
449
+ const getContext = () => {
450
+ return { mainContext, remove, item: Object.assign(Object.assign({}, props.item), { time, align }), index: props.index, mounted, getSvg };
451
+ };
452
+ return (_jsx(SBCTX.Provider, { value: getContext(), children: _jsx(SnackebarContainer, {}) }));
453
+ };
454
+ const SnackebarContainer = () => {
455
+ const { mainContext, mounted, index, item, remove } = useContext(SBCTX);
456
+ const { rtl } = mainContext;
457
+ let { onClose, align = ['right', 'top'] } = item;
458
+ function getOffsetStyle(index) {
459
+ let els = $('.aio-popup-snackebar-item-container'), sum = { top: 12, bottom: 12 };
460
+ for (let i = 0; i < index; i++) {
461
+ let dom = els.eq(i);
462
+ let height = dom.height() + 6;
463
+ let va = dom.attr('data-vertical-align');
464
+ sum[va] += height;
465
+ }
466
+ return {
467
+ [align[1] === 'top' ? 'top' : 'bottom']: sum[align[1]]
468
+ };
469
+ }
470
+ let className = 'aio-popup-snackebar-item-container';
471
+ className += ` aio-popup-snackebar-item-container-horizontal-align-${align[0]}`;
472
+ if (mounted) {
473
+ className += ' mounted';
474
+ }
475
+ if (rtl) {
476
+ className += ' rtl';
477
+ }
478
+ let style = getOffsetStyle(index);
479
+ let p = { 'data-vertical-align': align[1], className, style, onClick: onClose === false ? undefined : () => remove() };
480
+ return _jsx("div", Object.assign({}, p, { children: _jsx(SnackebarCard, {}) }));
481
+ };
482
+ const SnackebarCard = () => {
483
+ const { item } = useContext(SBCTX);
484
+ let { type, attrs = {} } = item;
485
+ let className = 'aio-popup-snackebar-item';
486
+ className += ` aio-popup-snackebar-item-${type}`;
487
+ if (attrs.className) {
488
+ className += ` ${attrs.className}`;
489
+ }
490
+ let p = Object.assign(Object.assign({}, attrs), { className, style: attrs.style });
491
+ return (_jsxs("div", Object.assign({}, p, { children: [_jsx(SnackebarIcon, {}), _jsx(SnackebarText, {}), _jsx(SnackebarAction, {}), _jsx(SnackebarBar, {})] })));
492
+ };
493
+ const SnackebarIcon = () => {
494
+ const { getSvg, item } = useContext(SBCTX);
495
+ return _jsx("div", { className: `aio-popup-snackebar-item-icon`, children: !!item.icon ? item.icon : getSvg(item.type) });
496
+ };
497
+ const SnackebarText = () => {
498
+ const { item } = useContext(SBCTX);
499
+ return (_jsxs("div", { className: 'aio-popup-snackebar-item-text', children: [_jsx("div", { className: 'aio-popup-snackebar-item-uptext', children: item.text }), !!item.subtext && _jsx("div", { className: 'aio-popup-snackebar-item-subtext', children: item.subtext })] }));
500
+ };
501
+ const SnackebarAction = () => {
502
+ const { item, remove } = useContext(SBCTX);
503
+ const { action } = item;
504
+ if (!action || !action.text) {
505
+ return null;
506
+ }
507
+ let p = {
508
+ className: 'aio-popup-snackebar-item-action',
509
+ onClick: (e) => { e.stopPropagation(); if (action) {
510
+ action.onClick();
511
+ } remove(); }
512
+ };
513
+ return (_jsx("button", Object.assign({}, p, { children: action.text })));
514
+ };
515
+ const SnackebarBar = () => {
516
+ const { item } = useContext(SBCTX);
517
+ return _jsx("div", { className: 'aio-popup-snackebar-bar', style: { transition: `${item.time || 8}s linear` } });
518
+ };
519
+ export function Alert(props) {
520
+ let { icon, type = '', text = '', subtext = '', time = 10, className, closeText = 'Close', onClose } = props;
521
+ let $$ = {
522
+ id: '',
523
+ time: 0,
524
+ getId() {
525
+ return 'aa' + Math.round((Math.random() * 100000000));
526
+ },
527
+ getBarRender() {
528
+ return `<div class='aio-popup-time-bar' style="width:${$$.time}%;"></div>`;
529
+ },
530
+ updateBarRender() {
531
+ $(`.aio-popup-alert-container.${$$.id} .aio-popup-time`).html($$.getBarRender());
532
+ },
533
+ getRender() {
534
+ return (`
535
+ <div class='aio-popup-alert-container not-mounted ${$$.id} aio-popup-alert-container-center${!!className ? ` ${className}` : ''}'>
536
+ <div class='aio-popup-alert aio-popup-alert-${type}'>
537
+ <div class='aio-popup-alert-header'>${$$.getIcon()}</div>
538
+ <div class='aio-popup-alert-body aio-popup-scroll'>
539
+ <div class='aio-popup-alert-text'>${ReactDOMServer.renderToStaticMarkup(text)}</div>
540
+ <div class='aio-popup-alert-subtext'>${subtext}</div>
541
+ </div>
542
+ <div class='aio-popup-alert-footer'>
543
+ <button class='aio-popup-alert-close ${$$.id}'>${closeText}</button>
544
+ </div>
545
+ <div class='aio-popup-time'></div>
546
+ </div>
547
+ </div>
548
+ `);
549
+ },
550
+ close() {
551
+ $$.toggleClass(false);
552
+ setTimeout(() => {
553
+ if (typeof onClose === 'function') {
554
+ onClose();
555
+ }
556
+ if (onClose === false) {
557
+ return;
558
+ }
559
+ $('.' + $$.id).remove();
560
+ }, 200);
561
+ },
562
+ getIcon() {
563
+ if (icon === false) {
564
+ return '';
565
+ }
566
+ return icon || {
567
+ 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>`),
568
+ 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>`),
569
+ 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>`),
570
+ 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>`)
571
+ }[type] || '';
572
+ },
573
+ startTimer() {
574
+ setTimeout(() => {
575
+ if ($$.time >= 100) {
576
+ $$.time = 100;
577
+ $$.close();
578
+ return;
579
+ }
580
+ $$.time += 2;
581
+ $$.updateBarRender();
582
+ $$.startTimer();
583
+ }, time / 50 * 1000);
584
+ },
585
+ toggleClass(mount) {
586
+ let dom = $(`.${$$.id}`);
587
+ if (mount) {
588
+ setTimeout(() => dom.removeClass('not-mounted'), 0);
589
+ }
590
+ else {
591
+ dom.addClass('not-mounted');
592
+ }
593
+ },
594
+ render() {
595
+ $('body').append($$.getRender());
596
+ $('button.' + $$.id).off('click', $$.close);
597
+ $('button.' + $$.id).on('click', $$.close);
598
+ $$.toggleClass(true);
599
+ }
600
+ };
601
+ $$.id = $$.getId();
602
+ $$.render();
603
+ if (time) {
604
+ $$.startTimer();
605
+ }
606
+ }
607
+ const Highlight = ({ highlight }) => {
608
+ const [limit, setLimit] = useState({ Left: 0, Top: 0, Width: 0, Height: 0, TopSpace: 0, BottomSpace: 0 });
609
+ const limitRef = useRef(limit);
610
+ limitRef.current = limit;
611
+ useEffect(() => {
612
+ setTimeout(() => {
613
+ try {
614
+ const { dom, duration = 1200 } = highlight;
615
+ dom[0].scrollIntoView();
616
+ let newLimit = getHLLimit(highlight);
617
+ let easing = getEasing(highlight);
618
+ let obj = Object.assign(Object.assign({}, newLimit), { targets: [Object.assign({}, limitRef.current)], duration, update: (p) => {
619
+ const { animatables } = p;
620
+ setLimit(Object.assign({}, animatables[0].target));
621
+ } });
622
+ if (easing) {
623
+ obj.easing = easing;
624
+ }
625
+ anime(obj);
626
+ }
627
+ catch (_a) {
628
+ alert(`aio-highlighter error => connot find dom`);
629
+ }
630
+ }, 0);
631
+ });
632
+ function getArrowIcon(props) {
633
+ return (_jsx("svg", Object.assign({ version: "1.1", id: "Layer_1", xmlns: "http://www.w3.org/2000/svg", x: "0px", y: "0px", viewBox: "0 0 512 512" }, props, { children: _jsxs("g", { children: [_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\r\n 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" }), _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\r\n 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" })] }) })));
634
+ }
635
+ function getArrow(dir, left, width) {
636
+ let center = left + width / 2, Left = center - 12;
637
+ let style = { position: 'absolute', height: 24, width: 24, left: Left };
638
+ let props = { width: 24, height: 24, style, className: `aio-popup-highlight-arrow-${dir}` };
639
+ return (_jsx("div", { className: "aio-popup-highlight-arrow", children: getArrowIcon(props) }));
640
+ }
641
+ function getHtml(dir) {
642
+ if (!highlight.html) {
643
+ return '';
644
+ }
645
+ let column;
646
+ let html = highlight.html || '';
647
+ let space = _jsx("div", { className: "aio-popup-highlight-space" });
648
+ let content = _jsx("div", { className: "aio-popup-highlight-html", children: html });
649
+ let arrow = getArrow(dir, limitRef.current.Left, limitRef.current.Width);
650
+ if (dir === 'top') {
651
+ column = _jsxs(_Fragment, { children: [space, content, arrow] });
652
+ }
653
+ else {
654
+ column = _jsxs(_Fragment, { children: [arrow, content, space] });
655
+ }
656
+ return _jsx("div", { className: "aio-popup-highlight-html-container", children: column });
657
+ }
658
+ function click() {
659
+ if (highlight.mouseAccess) {
660
+ return;
661
+ }
662
+ if (highlight.onClick) {
663
+ highlight.onClick();
664
+ }
665
+ }
666
+ function vMask_node(type) {
667
+ let html = '', size = 0, className = 'aio-popup-highlight-mask';
668
+ let dir = type === 'top' || type === 'bottom' ? 'height' : 'width';
669
+ let limit = limitRef.current;
670
+ if (type === 'top') {
671
+ size = limit.Top;
672
+ if (limit.TopSpace > limit.BottomSpace) {
673
+ html = getHtml('top');
674
+ }
675
+ }
676
+ else if (type === 'bottom') {
677
+ className += ' aio-popup-highlight-mask-flex';
678
+ if (limit.TopSpace <= limit.BottomSpace) {
679
+ html = getHtml('bottom');
680
+ }
681
+ }
682
+ else if (type === 'left') {
683
+ size = limit.Left;
684
+ }
685
+ else {
686
+ className += ' aio-popup-highlight-mask-flex';
687
+ }
688
+ return (_jsx("div", { className: className, style: { [dir]: size }, onClick: () => click(), children: html }));
689
+ }
690
+ function focus_node() {
691
+ const cls1 = "aio-popup-highlight-focus-container", cls2 = 'aio-popup-highlight-focus';
692
+ return (_jsx("div", { style: { width: limit.Width }, className: cls1, onClick: click, children: _jsx("div", { className: cls2 }) }));
693
+ }
694
+ function main_node() {
695
+ return _jsxs("div", { className: "aio-popup-highlight-main", style: { height: limit.Height }, children: [vMask_node('left'), focus_node(), vMask_node('right')] });
696
+ }
697
+ function getStyle() { return { pointerEvents: highlight.mouseAccess ? 'none' : 'all' }; }
698
+ const attrs = AddToAttrs(highlight.attrs, { className: 'aio-popup-highlight', style: getStyle() });
699
+ return (_jsxs("div", Object.assign({}, attrs, { children: [vMask_node('top'), main_node(), vMask_node('bottom')] })));
700
+ };
701
+ function getHLLimit(highlight) {
702
+ const { padding = 6, dom } = highlight;
703
+ let offset = dom.offset();
704
+ let left = offset.left - window.pageXOffset;
705
+ let top = offset.top - window.pageYOffset;
706
+ let pageHeight = window.innerHeight;
707
+ let width = dom.outerWidth();
708
+ let height = dom.outerHeight();
709
+ let Top = top - 1 * padding;
710
+ let Left = left - 1 * padding;
711
+ let Width = width + 2 * padding;
712
+ let Height = height + 2 * padding;
713
+ let TopSpace = top;
714
+ let BottomSpace = pageHeight - (top + height);
715
+ let res = { Left, Top, Width, Height, TopSpace, BottomSpace };
716
+ return res;
717
+ }
718
+ function getEasing(highlight) {
719
+ const { easing } = highlight;
720
+ var easingNames = [
721
+ 'linear',
722
+ 'easeInQuad',
723
+ 'easeInSine',
724
+ 'easeInCirc',
725
+ 'easeInBack',
726
+ 'easeOutQuad',
727
+ 'easeOutSine',
728
+ 'easeOutCirc',
729
+ 'easeInOutQuad',
730
+ 'easeInOutSine',
731
+ 'easeInOutBack',
732
+ 'easeOutBounce', //27
733
+ ];
734
+ if (typeof easing === 'number') {
735
+ let res = easingNames[easing];
736
+ return res || easingNames[0];
737
+ }
738
+ return easing;
739
+ }
740
+ const InfoSvg = () => {
741
+ const 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";
742
+ return (_jsx("svg", { viewBox: "0 0 24 24", role: "presentation", style: { width: '1.2rem', height: '1.2rem' }, children: _jsx("path", { d: d, style: { fill: 'currentcolor' } }) }));
743
+ };
744
+ const SuccessSvg = () => {
745
+ const 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";
746
+ return (_jsx("svg", { viewBox: "0 0 24 24", role: "presentation", style: { width: '1.2rem', height: '1.2rem' }, children: _jsx("path", { d: d, style: { fill: 'currentcolor' } }) }));
747
+ };
748
+ function getBound(dom) {
749
+ try {
750
+ const res = dom.getBoundingClientRect();
751
+ return { width: res.width, height: res.height, left: res.left, top: res.top, bottom: res.bottom, right: res.right };
752
+ }
753
+ catch (_a) {
754
+ return { width: 0, height: 0, left: 0, top: 0, bottom: 0, right: 0 };
755
+ }
756
+ }
757
+ export class Loading {
758
+ constructor(loader) {
759
+ this.loader = '0';
760
+ this.getLoader_0 = () => {
761
+ return (`
762
+ <div class="aio-loading-container-0">
763
+ <div class="aio-loading-0">
764
+ ${new Array(5).fill(0).map((o, i) => this.getLoaderItem_0(`0.${i}`)).join(' ')}
765
+ </div>
766
+ </div>
767
+ `);
768
+ };
769
+ this.getLoaderItem_0 = (ease) => {
770
+ return `<div class="aio-loading-item-0" style="animation: 1s ease-in-out ${ease}s infinite normal none running aioloading0;"></div>`;
771
+ };
772
+ this.getLoader = (id) => {
773
+ let content = '';
774
+ if (this.loader === '0') {
775
+ content = this.getLoader_0();
776
+ }
777
+ else if (typeof this.loader === 'string') {
778
+ content = this.loader;
779
+ }
780
+ return (`<div class="aio-loading" id="aio-loading-${id}">${content}</div>`);
781
+ };
782
+ this.show = (id, parentSelector) => {
783
+ parentSelector = parentSelector || 'body';
784
+ let loadingStr = this.getLoader(id);
785
+ let parent = document.querySelector(parentSelector);
786
+ if (parent) {
787
+ parent.insertAdjacentHTML('beforeend', loadingStr);
788
+ }
789
+ };
790
+ this.hide = (id) => {
791
+ let loadingDom = document.getElementById('aio-loading-' + id);
792
+ if (!loadingDom) {
793
+ loadingDom = document.querySelector('.aio-loading');
794
+ }
795
+ if (loadingDom) {
796
+ loadingDom.remove();
797
+ }
798
+ };
799
+ if (typeof loader === 'string') {
800
+ this.loader = loader;
801
+ }
802
+ }
803
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-popup",
3
- "version": "5.0.0",
3
+ "version": "6.0.0",
4
4
  "description": "handle all types of popup and modals in react",
5
5
  "main": "index.js",
6
6
  "scripts": {