UNPKG

primereact

Version:

PrimeReact is an open source UI library for React featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with Prime

2 lines (1 loc) 12.6 kB
this.primereact=this.primereact||{},this.primereact.dialog=function(e,t,n,r,a,o,l,i){"use strict";function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function c(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var s=c(t),d=u(n);function m(){return m=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},m.apply(this,arguments)}function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function f(e){if(Array.isArray(e))return p(e)}function g(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function b(e,t){if(e){if("string"==typeof e)return p(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?p(e,t):void 0}}function y(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function h(e){if(Array.isArray(e))return e}function v(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,a,o,l,i=[],u=!0,c=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;u=!1}else for(;!(u=(r=o.call(n)).done)&&(i.push(r.value),i.length!==t);u=!0);}catch(e){c=!0,a=e}finally{try{if(!u&&null!=n.return&&(l=n.return(),Object(l)!==l))return}finally{if(c)throw a}}return i}}function E(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function D(e,t){return h(e)||v(e,t)||b(e,t)||E()}var w={defaultProps:{__TYPE:"Dialog",appendTo:null,ariaCloseIconLabel:null,baseZIndex:0,blockScroll:!1,breakpoints:null,className:null,closable:!0,closeOnEscape:!0,contentClassName:null,contentStyle:null,dismissableMask:!1,draggable:!0,focusOnShow:!0,footer:null,header:null,headerClassName:null,headerStyle:null,icons:null,id:null,keepInViewport:!0,maskClassName:null,maskStyle:null,maximizable:!1,maximized:!1,minX:0,minY:0,modal:!0,onClick:null,onDrag:null,onDragEnd:null,onDragStart:null,onHide:null,onMaskClick:null,onMaximize:null,onResize:null,onResizeEnd:null,onResizeStart:null,onShow:null,position:"center",resizable:!0,rtl:!1,showHeader:!0,style:null,transitionOptions:null,visible:!1,children:void 0},getProps:function(e){return i.ObjectUtils.getMergedProps(e,w.defaultProps)},getOtherProps:function(e){return i.ObjectUtils.getDiffProps(e,w.defaultProps)}},S=s.forwardRef((function(e,t){var u=w.getProps(e),c=u.id?u.id:i.UniqueComponentId(),p=D(s.useState(c),2),h=p[0],v=D(s.useState(!1),2),E=v[0],S=v[1],x=D(s.useState(!1),2),k=x[0],z=x[1],C=D(s.useState(u.maximized),2),O=C[0],H=C[1],R=s.useRef(null),N=s.useRef(null),P=s.useRef(null),I=s.useRef(null),j=s.useRef(null),M=s.useRef(null),U=s.useRef(!1),X=s.useRef(!1),A=s.useRef(null),T=s.useRef(null),Y=s.useRef(null),_=s.useRef(c),L=u.onMaximize?u.maximized:O,B=D(a.useEventListener({type:"keydown",listener:function(e){return ie(e)}}),2),Z=B[0],V=B[1],J=D(a.useEventListener({type:"mousemove",target:function(){return window.document},listener:function(e){return pe(e)}}),2),W=J[0],F=J[1],$=D(a.useEventListener({type:"mouseup",target:function(){return window.document},listener:function(e){return fe(e)}}),2),q=$[0],K=$[1],G=D(a.useEventListener({type:"mousemove",target:function(){return window.document},listener:function(e){return ce(e)}}),2),Q=G[0],ee=G[1],te=D(a.useEventListener({type:"mouseup",target:function(){return window.document},listener:function(e){return se(e)}}),2),ne=te[0],re=te[1],ae=function(e){u.onHide(),e.preventDefault()},oe=function(e){u.dismissableMask&&u.modal&&N.current===e.target&&ae(e),u.onMaskClick&&u.onMaskClick(e)},le=function(e){u.onMaximize?u.onMaximize({originalEvent:e,maximized:!L}):H((function(e){return!e})),e.preventDefault()},ie=function(e){var t=e.currentTarget;if(t&&t.primeDialogParams){var n=t.primeDialogParams,r=n.length,a=n[r-1]?n[r-1].id:void 0;if(a===h){var o=document.getElementById(a);if(u.closable&&u.closeOnEscape&&"Escape"===e.key)ae(e),e.stopImmediatePropagation(),n.splice(r-1,1);else if("Tab"===e.key){e.preventDefault();var l=i.DomHandler.getFocusableElements(o);if(l&&l.length>0)if(document.activeElement){var c=l.indexOf(document.activeElement);e.shiftKey?-1===c||0===c?l[l.length-1].focus():l[c-1].focus():-1===c||c===l.length-1?l[0].focus():l[c+1].focus()}else l[0].focus()}}}},ue=function(e){i.DomHandler.hasClass(e.target,"p-dialog-header-icon")||i.DomHandler.hasClass(e.target.parentElement,"p-dialog-header-icon")||u.draggable&&(U.current=!0,A.current=e.pageX,T.current=e.pageY,R.current.style.margin="0",i.DomHandler.addClass(document.body,"p-unselectable-text"),u.onDragStart&&u.onDragStart(e))},ce=function(e){if(U.current){var t=i.DomHandler.getOuterWidth(R.current),n=i.DomHandler.getOuterHeight(R.current),r=e.pageX-A.current,a=e.pageY-T.current,o=R.current.getBoundingClientRect(),l=o.left+r,c=o.top+a,s=i.DomHandler.getViewport();R.current.style.position="fixed",u.keepInViewport?(l>=u.minX&&l+t<s.width&&(A.current=e.pageX,R.current.style.left=l+"px"),c>=u.minY&&c+n<s.height&&(T.current=e.pageY,R.current.style.top=c+"px")):(A.current=e.pageX,R.current.style.left=l+"px",T.current=e.pageY,R.current.style.top=c+"px"),u.onDrag&&u.onDrag(e)}},se=function(e){U.current&&(U.current=!1,i.DomHandler.removeClass(document.body,"p-unselectable-text"),u.onDragEnd&&u.onDragEnd(e))},de=function(e){u.resizable&&(X.current=!0,A.current=e.pageX,T.current=e.pageY,i.DomHandler.addClass(document.body,"p-unselectable-text"),u.onResizeStart&&u.onResizeStart(e))},me=function(e,t,n){!n&&(n=i.DomHandler.getViewport());var r=parseInt(e);return/^(\d+|(\.\d+))(\.\d+)?%$/.test(e)?r*(n[t]/100):r},pe=function(e){if(X.current){var t=e.pageX-A.current,n=e.pageY-T.current,r=i.DomHandler.getOuterWidth(R.current),a=i.DomHandler.getOuterHeight(R.current),o=R.current.getBoundingClientRect(),l=i.DomHandler.getViewport(),c=!parseInt(R.current.style.top)||!parseInt(R.current.style.left),s=me(R.current.style.minWidth,"width",l),d=me(R.current.style.minHeight,"height",l),m=r+t,p=a+n;c&&(m+=t,p+=n),(!s||m>s)&&o.left+m<l.width&&(R.current.style.width=m+"px"),(!d||p>d)&&o.top+p<l.height&&(R.current.style.height=p+"px"),A.current=e.pageX,T.current=e.pageY,u.onResize&&u.onResize(e)}},fe=function(e){X.current&&(X.current=!1,i.DomHandler.removeClass(document.body,"p-unselectable-text"),u.onResizeEnd&&u.onResizeEnd(e))},ge=function(){R.current.style.position="",R.current.style.left="",R.current.style.top="",R.current.style.margin=""},be=function(){R.current.setAttribute(_.current,"")},ye=function(){var e;u.onShow&&u.onShow(),u.focusOnShow&&!((e=document.activeElement)&&R.current&&R.current.contains(e))&&u.closable&&u.showHeader&&M.current.focus(),Ee()},he=function(){u.modal&&i.DomHandler.addClass(N.current,"p-component-overlay-leave"),u.blockScroll&&i.DomHandler.removeClass(document.body,"p-overflow-hidden")},ve=function(){U.current=!1,i.ZIndexUtils.clear(N.current),S(!1),De()},Ee=function(){we(),(u.blockScroll||u.maximizable&&L)&&i.DomHandler.addClass(document.body,"p-overflow-hidden")},De=function(){Se();var e=u.maximizable&&L;u.modal?(document.primeDialogParams&&document.primeDialogParams.some((function(e){return e.hasBlockScroll}))||e)&&i.DomHandler.removeClass(document.body,"p-overflow-hidden"):(u.blockScroll||e)&&i.DomHandler.removeClass(document.body,"p-overflow-hidden")},we=function(){u.draggable&&(Q(),ne()),u.resizable&&(W(),q()),Z();var e,t={id:h,hasBlockScroll:u.blockScroll};document.primeDialogParams=document.primeDialogParams?[].concat(f(e=document.primeDialogParams)||g(e)||b(e)||y(),[t]):[t]},Se=function(){ee(),re(),F(),K(),V(),document.primeDialogParams=document.primeDialogParams&&document.primeDialogParams.filter((function(e){return e.id!==h}))},xe=function(){Y.current=i.DomHandler.createInlineStyle(d.default.nonce);var e="";for(var t in u.breakpoints)e+="\n @media screen and (max-width: ".concat(t,") {\n .p-dialog[").concat(_.current,"] {\n width: ").concat(u.breakpoints[t]," !important;\n }\n }\n ");Y.current.innerHTML=e};a.useMountEffect((function(){u.visible&&S(!0),u.breakpoints&&xe()})),a.useUpdateEffect((function(){u.visible&&!E&&S(!0),u.visible!==k&&E&&z(u.visible)})),a.useUpdateEffect((function(){E&&(i.ZIndexUtils.set("modal",N.current,d.default.autoZIndex,u.baseZIndex||d.default.zIndex.modal),z(!0))}),[E]),a.useUpdateEffect((function(){u.blockScroll||i.DomHandler[L?"addClass":"removeClass"](document.body,"p-overflow-hidden")}),[u.maximized,O]),a.useUnmountEffect((function(){De(),i.DomHandler.removeInlineStyle(Y.current),i.ZIndexUtils.clear(N.current)})),s.useImperativeHandle(t,(function(){return{props:u,resetPosition:ge,getElement:function(){return R.current},getMask:function(){return N.current},getContent:function(){return P.current},getHeader:function(){return I.current},getFooter:function(){return j.current},getCloseButton:function(){return M.current}}}));var ke,ze,Ce,Oe,He,Re,Ne,Pe,Ie,je=function(){if(u.closable){var e=u.ariaCloseIconLabel||n.localeOption("close");return s.createElement("button",{ref:M,type:"button",className:"p-dialog-header-icon p-dialog-header-close p-link","aria-label":e,onClick:ae},s.createElement("span",{className:"p-dialog-header-close-icon pi pi-times","aria-hidden":"true"}),s.createElement(l.Ripple,null))}return null},Me=function(){if(u.showHeader){var e=je(),t=(c=i.classNames("p-dialog-header-maximize-icon pi",{"pi-window-maximize":!L,"pi-window-minimize":L}),u.maximizable?s.createElement("button",{type:"button",className:"p-dialog-header-icon p-dialog-header-maximize p-link",onClick:le},s.createElement("span",{className:c}),s.createElement(l.Ripple,null)):null),n=i.ObjectUtils.getJSXElement(u.icons,u),r=i.ObjectUtils.getJSXElement(u.header,u),a=h+"_header",o=i.classNames("p-dialog-header",u.headerClassName);return s.createElement("div",{ref:I,style:u.headerStyle,className:o,onMouseDown:ue},s.createElement("div",{id:a,className:"p-dialog-title"},r),s.createElement("div",{className:"p-dialog-header-icons"},n,t,e))}var c;return null},Ue=function(){var e=i.classNames("p-dialog-content",u.contentClassName);return s.createElement("div",{id:h+"_content",ref:P,className:e,style:u.contentStyle},u.children)},Xe=function(){var e=i.ObjectUtils.getJSXElement(u.footer,u);return e&&s.createElement("div",{ref:j,className:"p-dialog-footer"},e)};return E&&(ze=w.getOtherProps(u),Ce=i.classNames("p-dialog p-component",u.className,{"p-dialog-rtl":u.rtl,"p-dialog-maximized":L,"p-dialog-default":!L,"p-input-filled":"filled"===d.default.inputStyle,"p-ripple-disabled":!1===d.default.ripple}),Oe=i.classNames("p-dialog-mask",(ke=["center","left","right","top","top-left","top-right","bottom","bottom-left","bottom-right"].find((function(e){return e===u.position||e.replace("-","")===u.position})))?"p-dialog-".concat(ke):"",{"p-component-overlay p-component-overlay-enter":u.modal,"p-dialog-visible":E,"p-dialog-draggable":u.draggable,"p-dialog-resizable":u.resizable},u.maskClassName),He=Me(),Re=Ue(),Ne=Xe(),Pe=u.resizable?s.createElement("span",{className:"p-resizable-handle",style:{zIndex:90},onMouseDown:de}):null,Ie=s.createElement("div",{ref:N,style:u.maskStyle,className:Oe,onClick:oe},s.createElement(r.CSSTransition,{nodeRef:R,classNames:"p-dialog",timeout:{enter:"center"===u.position?150:300,exit:"center"===u.position?150:300},in:k,options:u.transitionOptions,unmountOnExit:!0,onEnter:be,onEntered:ye,onExiting:he,onExited:ve},s.createElement("div",m({ref:R,id:h,className:Ce,style:u.style,onClick:u.onClick,role:"dialog"},ze,{"aria-labelledby":h+"_header","aria-describedby":h+"_content","aria-modal":u.modal}),He,Re,Ne,Pe))),s.createElement(o.Portal,{element:Ie,appendTo:u.appendTo,visible:!0}))}));return S.displayName="Dialog",e.Dialog=S,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.api,primereact.csstransition,primereact.hooks,primereact.portal,primereact.ripple,primereact.utils);