UNPKG

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
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/api"),n=require("primereact/csstransition"),r=require("primereact/hooks"),a=require("primereact/portal"),o=require("primereact/ripple"),l=require("primereact/utils");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function u(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 c=u(e),s=i(t);function d(){return d=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},d.apply(this,arguments)}function m(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 p(e){if(Array.isArray(e))return m(e)}function f(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function g(e,t){if(e){if("string"==typeof e)return m(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)?m(e,t):void 0}}function b(){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 y(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 h(){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 E(e,t){return y(e)||v(e,t)||g(e,t)||h()}var D=c.forwardRef((function(e,i){var u=E(c.useState(e.id),2),m=u[0],y=u[1],v=E(c.useState(!1),2),h=v[0],w=v[1],x=E(c.useState(!1),2),S=x[0],k=x[1],z=E(c.useState(e.maximized),2),C=z[0],H=z[1],O=c.useRef(null),N=c.useRef(null),R=c.useRef(null),I=c.useRef(null),P=c.useRef(null),j=c.useRef(null),M=c.useRef(!1),U=c.useRef(!1),X=c.useRef(null),A=c.useRef(null),T=c.useRef(null),Y=c.useRef(""),_=e.onMaximize?e.maximized:C,q=E(r.useEventListener({type:"keydown",listener:function(e){return le(e)}}),2),L=q[0],B=q[1],Z=E(r.useEventListener({type:"mousemove",target:function(){return window.document},listener:function(e){return me(e)}}),2),V=Z[0],J=Z[1],W=E(r.useEventListener({type:"mouseup",target:function(){return window.document},listener:function(e){return pe(e)}}),2),F=W[0],K=W[1],$=E(r.useEventListener({type:"mousemove",target:function(){return window.document},listener:function(e){return ue(e)}}),2),G=$[0],Q=$[1],ee=E(r.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&&N.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===m){var i=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=l.DomHandler.getFocusableElements(i);if(u&&u.length>0)if(document.activeElement){var c=u.indexOf(document.activeElement);t.shiftKey?-1===c||0===c?u[u.length-1].focus():u[c-1].focus():-1===c||c===u.length-1?u[0].focus():u[c+1].focus()}else u[0].focus()}}}},ie=function(t){l.DomHandler.hasClass(t.target,"p-dialog-header-icon")||l.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",l.DomHandler.addClass(document.body,"p-unselectable-text"),e.onDragStart&&e.onDragStart(t))},ue=function(t){if(M.current){var n=l.DomHandler.getOuterWidth(O.current),r=l.DomHandler.getOuterHeight(O.current),a=t.pageX-X.current,o=t.pageY-A.current,i=O.current.getBoundingClientRect(),u=i.left+a,c=i.top+o,s=l.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,l.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,l.DomHandler.addClass(document.body,"p-unselectable-text"),e.onResizeStart&&e.onResizeStart(t))},de=function(e,t,n){!n&&(n=l.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=l.DomHandler.getOuterWidth(O.current),o=l.DomHandler.getOuterHeight(O.current),i=O.current.getBoundingClientRect(),u=l.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)&&i.left+m<u.width&&(O.current.style.width=m+"px"),(!d||p>d)&&i.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,l.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(),he()},ye=function(){e.modal&&l.DomHandler.addClass(N.current,"p-component-overlay-leave"),e.blockScroll&&l.DomHandler.removeClass(document.body,"p-overflow-hidden")},ve=function(){M.current=!1,l.ZIndexUtils.clear(N.current),w(!1),Ee()},he=function(){De(),(e.blockScroll||e.maximizable&&_)&&l.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)&&l.DomHandler.removeClass(document.body,"p-overflow-hidden"):(e.blockScroll||t)&&l.DomHandler.removeClass(document.body,"p-overflow-hidden")},De=function(){e.draggable&&(G(),te()),e.resizable&&(V(),F()),L();var t,n={id:m,hasBlockScroll:e.blockScroll};document.primeDialogParams=document.primeDialogParams?[].concat(p(t=document.primeDialogParams)||f(t)||g(t)||b(),[n]):[n]},we=function(){Q(),ne(),J(),K(),B(),document.primeDialogParams=document.primeDialogParams&&document.primeDialogParams.filter((function(e){return e.id!==m}))},xe=function(){if(!T.current){T.current=l.DomHandler.createInlineStyle(s.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}};r.useMountEffect((function(){var t=l.UniqueComponentId();m||y(t),Y.current||(Y.current=t),e.visible&&w(!0),e.breakpoints&&xe()})),r.useUpdateEffect((function(){e.visible&&!h&&w(!0),e.visible!==S&&h&&k(e.visible)})),r.useUpdateEffect((function(){h&&(l.ZIndexUtils.set("modal",N.current,s.default.autoZIndex,e.baseZIndex||s.default.zIndex.modal),k(!0))}),[h]),r.useUpdateEffect((function(){e.blockScroll||l.DomHandler[_?"addClass":"removeClass"](document.body,"p-overflow-hidden")}),[e.maximized,C]),r.useUnmountEffect((function(){Ee(),l.DomHandler.removeInlineStyle(T.current),l.ZIndexUtils.clear(N.current)})),c.useImperativeHandle(i,(function(){return{props:e,resetPosition:fe,getElement:function(){return O.current},getMask:function(){return N.current},getContent:function(){return R.current},getHeader:function(){return I.current},getFooter:function(){return P.current},getCloseButton:function(){return j.current}}}));var Se,ke,ze,Ce,He,Oe,Ne,Re,Ie,Pe=function(){if(e.closable){var n=e.ariaCloseIconLabel||t.localeOption("close");return c.createElement("button",{ref:j,type:"button",className:"p-dialog-header-icon p-dialog-header-close p-link","aria-label":n,onClick:re},c.createElement("span",{className:"p-dialog-header-close-icon pi pi-times","aria-hidden":"true"}),c.createElement(o.Ripple,null))}return null},je=function(){if(e.showHeader){var t=Pe(),n=(s=l.classNames("p-dialog-header-maximize-icon pi",{"pi-window-maximize":!_,"pi-window-minimize":_}),e.maximizable?c.createElement("button",{type:"button",className:"p-dialog-header-icon p-dialog-header-maximize p-link",onClick:oe},c.createElement("span",{className:s}),c.createElement(o.Ripple,null)):null),r=l.ObjectUtils.getJSXElement(e.icons,e),a=l.ObjectUtils.getJSXElement(e.header,e),i=m+"_header",u=l.classNames("p-dialog-header",e.headerClassName);return c.createElement("div",{ref:I,style:e.headerStyle,className:u,onMouseDown:ie},c.createElement("div",{id:i,className:"p-dialog-title"},a),c.createElement("div",{className:"p-dialog-header-icons"},r,n,t))}var s;return null},Me=function(){var t=l.classNames("p-dialog-content",e.contentClassName);return c.createElement("div",{id:m+"_content",ref:R,className:t,style:e.contentStyle},e.children)},Ue=function(){var t=l.ObjectUtils.getJSXElement(e.footer,e);return t&&c.createElement("div",{ref:P,className:"p-dialog-footer"},t)};return h&&(ke=l.ObjectUtils.findDiffKeys(e,D.defaultProps),ze=l.classNames("p-dialog p-component",e.className,{"p-dialog-rtl":e.rtl,"p-dialog-maximized":_}),Ce=l.classNames("p-dialog-mask",(Se=["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(Se):"",{"p-component-overlay p-component-overlay-enter":e.modal,"p-dialog-visible":h,"p-dialog-draggable":e.draggable,"p-dialog-resizable":e.resizable},e.maskClassName),He=je(),Oe=Me(),Ne=Ue(),Re=e.resizable?c.createElement("span",{className:"p-resizable-handle",style:{zIndex:90},onMouseDown:se}):null,Ie=c.createElement("div",{ref:N,style:e.maskStyle,className:Ce,onClick:ae},c.createElement(n.CSSTransition,{nodeRef:O,classNames:"p-dialog",timeout:{enter:"center"===e.position?150:300,exit:"center"===e.position?150:300},in:S,options:e.transitionOptions,unmountOnExit:!0,onEnter:ge,onEntered:be,onExiting:ye,onExited:ve},c.createElement("div",d({ref:O,id:m,className:ze,style:e.style,onClick:e.onClick,role:"dialog"},ke,{"aria-labelledby":m+"_header","aria-describedby":m+"_content","aria-modal":e.modal}),He,Oe,Ne,Re))),c.createElement(a.Portal,{element:Ie,appendTo:e.appendTo,visible:!0}))}));D.displayName="Dialog",D.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},exports.Dialog=D;