primereact
Version:
PrimeReact is an open source UI library for React featuring a rich set of 80+ 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.3 kB
JavaScript
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=!0,i=!1;try{for(n=n.call(e);!(l=(r=n.next()).done)&&(o.push(r.value),!t||o.length!==t);l=!0);}catch(e){i=!0,a=e}finally{try{l||null==n.return||n.return()}finally{if(i)throw a}}return o}}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=s.forwardRef((function(e,t){var u=D(s.useState(e.id),2),c=u[0],p=u[1],h=D(s.useState(!1),2),v=h[0],E=h[1],S=D(s.useState(!1),2),x=S[0],k=S[1],z=D(s.useState(e.maximized),2),C=z[0],H=z[1],O=s.useRef(null),R=s.useRef(null),N=s.useRef(null),I=s.useRef(null),P=s.useRef(null),j=s.useRef(null),M=s.useRef(!1),U=s.useRef(!1),X=s.useRef(null),A=s.useRef(null),T=s.useRef(null),Y=s.useRef(""),_=e.onMaximize?e.maximized:C,L=D(a.useEventListener({type:"keydown",listener:function(e){return le(e)}}),2),B=L[0],Z=L[1],V=D(a.useEventListener({type:"mousemove",target:function(){return window.document},listener:function(e){return me(e)}}),2),J=V[0],W=V[1],F=D(a.useEventListener({type:"mouseup",target:function(){return window.document},listener:function(e){return pe(e)}}),2),K=F[0],$=F[1],q=D(a.useEventListener({type:"mousemove",target:function(){return window.document},listener:function(e){return ue(e)}}),2),G=q[0],Q=q[1],ee=D(a.useEventListener({type:"mouseup",target:function(){return window.document},listener:function(e){return ce(e)}}),2),te=ee[0],ne=ee[1],re=function(t){e.onHide(),t.preventDefault()},ae=function(t){e.dismissableMask&&e.modal&&R.current===t.target&&re(t),e.onMaskClick&&e.onMaskClick(t)},oe=function(t){e.onMaximize?e.onMaximize({originalEvent:t,maximized:!_}):H((function(e){return!e})),t.preventDefault()},le=function(t){var n=t.currentTarget;if(n&&n.primeDialogParams){var r=n.primeDialogParams,a=r.length,o=r[a-1]?r[a-1].id:void 0;if(o===c){var l=document.getElementById(o);if(e.closable&&e.closeOnEscape&&"Escape"===t.key)re(t),t.stopImmediatePropagation(),r.splice(a-1,1);else if("Tab"===t.key){t.preventDefault();var u=i.DomHandler.getFocusableElements(l);if(u&&u.length>0)if(document.activeElement){var s=u.indexOf(document.activeElement);t.shiftKey?-1===s||0===s?u[u.length-1].focus():u[s-1].focus():-1===s||s===u.length-1?u[0].focus():u[s+1].focus()}else u[0].focus()}}}},ie=function(t){i.DomHandler.hasClass(t.target,"p-dialog-header-icon")||i.DomHandler.hasClass(t.target.parentElement,"p-dialog-header-icon")||e.draggable&&(M.current=!0,X.current=t.pageX,A.current=t.pageY,O.current.style.margin="0",i.DomHandler.addClass(document.body,"p-unselectable-text"),e.onDragStart&&e.onDragStart(t))},ue=function(t){if(M.current){var n=i.DomHandler.getOuterWidth(O.current),r=i.DomHandler.getOuterHeight(O.current),a=t.pageX-X.current,o=t.pageY-A.current,l=O.current.getBoundingClientRect(),u=l.left+a,c=l.top+o,s=i.DomHandler.getViewport();O.current.style.position="fixed",e.keepInViewport?(u>=e.minX&&u+n<s.width&&(X.current=t.pageX,O.current.style.left=u+"px"),c>=e.minY&&c+r<s.height&&(A.current=t.pageY,O.current.style.top=c+"px")):(X.current=t.pageX,O.current.style.left=u+"px",A.current=t.pageY,O.current.style.top=c+"px"),e.onDrag&&e.onDrag(t)}},ce=function(t){M.current&&(M.current=!1,i.DomHandler.removeClass(document.body,"p-unselectable-text"),e.onDragEnd&&e.onDragEnd(t))},se=function(t){e.resizable&&(U.current=!0,X.current=t.pageX,A.current=t.pageY,i.DomHandler.addClass(document.body,"p-unselectable-text"),e.onResizeStart&&e.onResizeStart(t))},de=function(e,t,n){!n&&(n=i.DomHandler.getViewport());var r=parseInt(e);return/^(\d+|(\.\d+))(\.\d+)?%$/.test(e)?r*(n[t]/100):r},me=function(t){if(U.current){var n=t.pageX-X.current,r=t.pageY-A.current,a=i.DomHandler.getOuterWidth(O.current),o=i.DomHandler.getOuterHeight(O.current),l=O.current.getBoundingClientRect(),u=i.DomHandler.getViewport(),c=!parseInt(O.current.style.top)||!parseInt(O.current.style.left),s=de(O.current.style.minWidth,"width",u),d=de(O.current.style.minHeight,"height",u),m=a+n,p=o+r;c&&(m+=n,p+=r),(!s||m>s)&&l.left+m<u.width&&(O.current.style.width=m+"px"),(!d||p>d)&&l.top+p<u.height&&(O.current.style.height=p+"px"),X.current=t.pageX,A.current=t.pageY,e.onResize&&e.onResize(t)}},pe=function(t){U.current&&(U.current=!1,i.DomHandler.removeClass(document.body,"p-unselectable-text"),e.onResizeEnd&&e.onResizeEnd(t))},fe=function(){O.current.style.position="",O.current.style.left="",O.current.style.top="",O.current.style.margin=""},ge=function(){O.current.setAttribute(Y.current,"")},be=function(){var t;e.onShow&&e.onShow(),e.focusOnShow&&!((t=document.activeElement)&&O.current&&O.current.contains(t))&&e.closable&&e.showHeader&&j.current.focus(),ve()},ye=function(){e.modal&&i.DomHandler.addClass(R.current,"p-component-overlay-leave"),e.blockScroll&&i.DomHandler.removeClass(document.body,"p-overflow-hidden")},he=function(){M.current=!1,i.ZIndexUtils.clear(R.current),E(!1),Ee()},ve=function(){De(),(e.blockScroll||e.maximizable&&_)&&i.DomHandler.addClass(document.body,"p-overflow-hidden")},Ee=function(){we();var t=e.maximizable&&_;e.modal?(document.primeDialogParams&&document.primeDialogParams.some((function(e){return e.hasBlockScroll}))||t)&&i.DomHandler.removeClass(document.body,"p-overflow-hidden"):(e.blockScroll||t)&&i.DomHandler.removeClass(document.body,"p-overflow-hidden")},De=function(){e.draggable&&(G(),te()),e.resizable&&(J(),K()),B();var t,n={id:c,hasBlockScroll:e.blockScroll};document.primeDialogParams=document.primeDialogParams?[].concat(f(t=document.primeDialogParams)||g(t)||b(t)||y(),[n]):[n]},we=function(){Q(),ne(),W(),$(),Z(),document.primeDialogParams=document.primeDialogParams&&document.primeDialogParams.filter((function(e){return e.id!==c}))},Se=function(){if(!T.current){T.current=i.DomHandler.createInlineStyle(d.default.nonce);var t="";for(var n in e.breakpoints)t+="\n @media screen and (max-width: ".concat(n,") {\n .p-dialog[").concat(Y.current,"] {\n width: ").concat(e.breakpoints[n]," !important;\n }\n }\n ");T.current.innerHTML=t}};a.useMountEffect((function(){var t=i.UniqueComponentId();c||p(t),Y.current||(Y.current=t),e.visible&&E(!0),e.breakpoints&&Se()})),a.useUpdateEffect((function(){e.visible&&!v&&E(!0),e.visible!==x&&v&&k(e.visible)})),a.useUpdateEffect((function(){v&&(i.ZIndexUtils.set("modal",R.current,d.default.autoZIndex,e.baseZIndex||d.default.zIndex.modal),k(!0))}),[v]),a.useUpdateEffect((function(){e.blockScroll||i.DomHandler[_?"addClass":"removeClass"](document.body,"p-overflow-hidden")}),[e.maximized,C]),a.useUnmountEffect((function(){Ee(),i.DomHandler.removeInlineStyle(T.current),i.ZIndexUtils.clear(R.current)})),s.useImperativeHandle(t,(function(){return{props:e,resetPosition:fe,getElement:function(){return O.current},getMask:function(){return R.current},getContent:function(){return N.current},getHeader:function(){return I.current},getFooter:function(){return P.current},getCloseButton:function(){return j.current}}}));var xe,ke,ze,Ce,He,Oe,Re,Ne,Ie,Pe=function(){if(e.closable){var t=e.ariaCloseIconLabel||n.localeOption("close");return s.createElement("button",{ref:j,type:"button",className:"p-dialog-header-icon p-dialog-header-close p-link","aria-label":t,onClick:re},s.createElement("span",{className:"p-dialog-header-close-icon pi pi-times","aria-hidden":"true"}),s.createElement(l.Ripple,null))}return null},je=function(){if(e.showHeader){var t=Pe(),n=(d=i.classNames("p-dialog-header-maximize-icon pi",{"pi-window-maximize":!_,"pi-window-minimize":_}),e.maximizable?s.createElement("button",{type:"button",className:"p-dialog-header-icon p-dialog-header-maximize p-link",onClick:oe},s.createElement("span",{className:d}),s.createElement(l.Ripple,null)):null),r=i.ObjectUtils.getJSXElement(e.icons,e),a=i.ObjectUtils.getJSXElement(e.header,e),o=c+"_header",u=i.classNames("p-dialog-header",e.headerClassName);return s.createElement("div",{ref:I,style:e.headerStyle,className:u,onMouseDown:ie},s.createElement("div",{id:o,className:"p-dialog-title"},a),s.createElement("div",{className:"p-dialog-header-icons"},r,n,t))}var d;return null},Me=function(){var t=i.classNames("p-dialog-content",e.contentClassName);return s.createElement("div",{id:c+"_content",ref:N,className:t,style:e.contentStyle},e.children)},Ue=function(){var t=i.ObjectUtils.getJSXElement(e.footer,e);return t&&s.createElement("div",{ref:P,className:"p-dialog-footer"},t)};return v&&(ke=i.ObjectUtils.findDiffKeys(e,w.defaultProps),ze=i.classNames("p-dialog p-component",e.className,{"p-dialog-rtl":e.rtl,"p-dialog-maximized":_}),Ce=i.classNames("p-dialog-mask",(xe=["center","left","right","top","top-left","top-right","bottom","bottom-left","bottom-right"].find((function(t){return t===e.position||t.replace("-","")===e.position})))?"p-dialog-".concat(xe):"",{"p-component-overlay p-component-overlay-enter":e.modal,"p-dialog-visible":v,"p-dialog-draggable":e.draggable,"p-dialog-resizable":e.resizable},e.maskClassName),He=je(),Oe=Me(),Re=Ue(),Ne=e.resizable?s.createElement("span",{className:"p-resizable-handle",style:{zIndex:90},onMouseDown:se}):null,Ie=s.createElement("div",{ref:R,style:e.maskStyle,className:Ce,onClick:ae},s.createElement(r.CSSTransition,{nodeRef:O,classNames:"p-dialog",timeout:{enter:"center"===e.position?150:300,exit:"center"===e.position?150:300},in:x,options:e.transitionOptions,unmountOnExit:!0,onEnter:ge,onEntered:be,onExiting:ye,onExited:he},s.createElement("div",m({ref:O,id:c,className:ze,style:e.style,onClick:e.onClick,role:"dialog"},ke,{"aria-labelledby":c+"_header","aria-describedby":c+"_content","aria-modal":e.modal}),He,Oe,Re,Ne))),s.createElement(o.Portal,{element:Ie,appendTo:e.appendTo,visible:!0}))}));return w.displayName="Dialog",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},e.Dialog=w,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.api,primereact.csstransition,primereact.hooks,primereact.portal,primereact.ripple,primereact.utils);