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) 17.1 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils"),n=require("primereact/api");function r(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 o=u(e),c=r(n);function i(e){if(Array.isArray(e))return e}function a(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,u,o,c,i=[],a=!0,l=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;a=!1}else for(;!(a=(r=o.call(n)).done)&&(i.push(r.value),i.length!==t);a=!0);}catch(e){l=!0,u=e}finally{try{if(!a&&null!=n.return&&(c=n.return(),Object(c)!==c))return}finally{if(l)throw u}}return i}}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function s(e,t){if(e){if("string"==typeof e)return l(e,t);var n={}.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)?l(e,t):void 0}}function f(){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 i(e)||a(e,t)||s(e,t)||f()}var p=function(e){var t=o.useRef(null);return o.useEffect((function(){return t.current=e,function(){t.current=null}}),[e]),t.current},v=function(e){return o.useEffect((function(){return e}),[])},y=function(e){var n=e.target,r=void 0===n?"document":n,u=e.type,c=e.listener,i=e.options,a=e.when,l=void 0===a||a,s=o.useRef(null),f=o.useRef(null),d=p(c),y=p(i),m=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.target;t.ObjectUtils.isNotEmpty(n)&&(g(),(e.when||l)&&(s.current=t.DomHandler.getTargetElement(n))),!f.current&&s.current&&(f.current=function(e){return c&&c(e)},s.current.addEventListener(u,f.current,i))},g=function(){f.current&&(s.current.removeEventListener(u,f.current,i),f.current=null)},h=function(){g(),d=null,y=null},b=o.useCallback((function(){l?s.current=t.DomHandler.getTargetElement(r):(g(),s.current=null)}),[r,l]);return o.useEffect((function(){b()}),[b]),o.useEffect((function(){var e="".concat(d)!=="".concat(c),t=f.current;t&&(e||y!==i)?(g(),l&&m()):t||h()}),[c,i,l]),v((function(){h()})),[m,g]},m={},g={ico:"image/x-icon",png:"image/png",svg:"image/svg+xml",gif:"image/gif"};function h(e){if(Array.isArray(e))return l(e)}function b(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function w(){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 E(e){return h(e)||b(e)||s(e)||w()}var O={escKeyListeners:new Map,onGlobalKeyDown:function(e){if("Escape"===e.code){var t=O.escKeyListeners,n=Math.max.apply(Math,E(t.keys())),r=t.get(n),u=Math.max.apply(Math,E(r.keys()));r.get(u)(e)}},refreshGlobalKeyDownListener:function(){var e=t.DomHandler.getTargetElement("document");this.escKeyListeners.size>0?e.addEventListener("keydown",this.onGlobalKeyDown):e.removeEventListener("keydown",this.onGlobalKeyDown)},addListener:function(e,t){var n=this,r=d(t,2),u=r[0],o=r[1],c=this.escKeyListeners;c.has(u)||c.set(u,new Map);var i=c.get(u);if(i.has(o))throw new Error("Unexpected: global esc key listener with priority [".concat(u,", ").concat(o,"] already exists."));return i.set(o,e),this.refreshGlobalKeyDownListener(),function(){i.delete(o),0===i.size&&c.delete(u),n.refreshGlobalKeyDownListener()}}},S=function(e){var t=o.useRef(!1);return o.useEffect((function(){if(!t.current)return t.current=!0,e&&e()}),[])};function x(e){return x="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},x(e)}function D(e,t){if("object"!=x(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=x(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function j(e){var t=D(e,"string");return"symbol"==x(t)?t:t+""}function P(e,t,n){return(t=j(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function L(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function R(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?L(Object(n),!0).forEach((function(t){P(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):L(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function I(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function C(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?I(Object(n),!0).forEach((function(t){P(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):I(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var A=function(e){var r=e.target,u=e.listener,i=e.options,a=e.when,l=void 0===a||a,s=o.useContext(n.PrimeReactContext),f=o.useRef(null),d=o.useRef(null),y=o.useRef([]),m=p(u),g=p(i),h=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(t.ObjectUtils.isNotEmpty(e.target)&&(b(),(e.when||l)&&(f.current=t.DomHandler.getTargetElement(e.target))),!d.current&&f.current){var n=s?s.hideOverlaysOnDocumentScrolling:c.default.hideOverlaysOnDocumentScrolling,r=y.current=t.DomHandler.getScrollableParents(f.current);r.some((function(e){return e===document.body||e===window}))||r.push(n?window:document.body),d.current=function(e){return u&&u(e)},r.forEach((function(e){return e.addEventListener("scroll",d.current,i)}))}},b=function(){d.current&&(y.current.forEach((function(e){return e.removeEventListener("scroll",d.current,i)})),d.current=null)},w=function(){b(),y.current=null,m=null,g=null},E=o.useCallback((function(){l?f.current=t.DomHandler.getTargetElement(r):(b(),f.current=null)}),[r,l]);return o.useEffect((function(){E()}),[E]),o.useEffect((function(){var e="".concat(m)!=="".concat(u),t=d.current;t&&(e||g!==i)?(b(),l&&h()):t||w()}),[u,i,l]),v((function(){w()})),[h,b]},T=function(e){var t=e.when;return y({target:"window",type:"resize",listener:e.listener,when:void 0===t||t})},M=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"local",r="undefined"!=typeof window,u=d(y({target:"window",type:"storage",listener:function(e){var r="local"===n?window.localStorage:window.sessionStorage;if(e.storageArea===r&&e.key===t){var u=e.newValue?JSON.parse(e.newValue):void 0;s(u)}}}),2),c=u[0],i=u[1],a=d(o.useState(e),2),l=a[0],s=a[1];return o.useEffect((function(){r||s(e);try{var u="local"===n?window.localStorage.getItem(t):window.sessionStorage.getItem(t);s(u?JSON.parse(u):e)}catch(t){s(e)}return c(),function(){return i()}}),[]),[l,function(e){try{var u=e instanceof Function?e(l):e;if(s(u),r){var o=JSON.stringify(u);"local"===n?window.localStorage.setItem(t,o):window.sessionStorage.setItem(t,o)}}catch(e){throw new Error("PrimeReact useStorage: Failed to serialize the value at key: ".concat(t))}}]},k=0;exports.ESC_KEY_HANDLING_PRIORITIES={SIDEBAR:100,SLIDE_MENU:200,DIALOG:300,IMAGE:400,MENU:500,OVERLAY_PANEL:600,PASSWORD:700,CASCADE_SELECT:800,SPLIT_BUTTON:900,SPEED_DIAL:1e3,TOOLTIP:1200},exports.useClickOutside=function(e,t){var n=function(n){e.current&&!e.current.contains(n.target)&&t(n)},r=d(y({type:"mousedown",listener:n}),2),u=r[0],c=r[1],i=d(y({type:"touchstart",listener:n}),2),a=i[0],l=i[1];return o.useEffect((function(){if(e.current)return u(),a(),function(){c(),l()}})),[e,t]},exports.useCounter=function(){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{step:1},t=d(o.useState(arguments.length>0&&void 0!==arguments[0]?arguments[0]:0),2),n=t[0],r=t[1];return{count:n,increment:function(){e.max&&n>=e.max||r(n+e.step)},decrement:function(){if(e.min||0===e.min&&n<=e.min)return null;r(n-e.step)},reset:function(){r(0)}}},exports.useDebounce=function(e,t){var n=d(o.useState(e),2),r=n[0],u=n[1],c=d(o.useState(e),2),i=c[0],a=c[1],l=o.useRef(!1),s=o.useRef(null),f=function(){return window.clearTimeout(s.current)};return S((function(){l.current=!0})),v((function(){f()})),o.useEffect((function(){l.current&&(f(),s.current=window.setTimeout((function(){a(r)}),t))}),[r,t]),[r,i,u]},exports.useDisplayOrder=function(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=d(o.useState((function(){return t.UniqueComponentId()})),1)[0],u=d(o.useState(0),2),c=u[0],i=u[1];return o.useEffect((function(){if(n){m[e]||(m[e]=[]);var u=m[e].push(r);return i(u),function(){delete m[e][u-1];var n=m[e].length-1,r=t.ObjectUtils.findLastIndex(m[e],(function(e){return void 0!==e}));r!==n&&m[e].splice(r+1),i(void 0)}}}),[e,r,n]),c},exports.useEventListener=y,exports.useFavicon=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"shortcut icon";o.useLayoutEffect((function(){if(e){document.querySelectorAll("link[rel*='icon']").forEach((function(e){document.head.removeChild(e)}));var n=document.createElement("link");n.setAttribute("type",g[e.split(".").pop()]),n.setAttribute("rel",t),n.setAttribute("href",e),document.head.appendChild(n)}}),[e,t])},exports.useGlobalOnEscapeKey=function(t){var n=t.callback,r=t.when,u=t.priority;e.useEffect((function(){if(r)return O.addListener(n,u)}),[n,r,u])},exports.useIntersectionObserver=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=d(o.useState(!1),2),r=n[0],u=n[1];return o.useEffect((function(){if(e.current){var n=new IntersectionObserver((function(e){var t=d(e,1);u(t[0].isIntersecting)}),t);return n.observe(e.current),function(){n.disconnect()}}}),[t,e]),r},exports.useInterval=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=o.useRef(null),u=o.useRef(null),c=o.useCallback((function(){return clearInterval(r.current)}),[r.current]);return o.useEffect((function(){u.current=e})),o.useEffect((function(){if(n)return r.current=setInterval((function(){u.current()}),t),c;c()}),[t,n]),v((function(){c()})),[c]},exports.useLocalStorage=function(e,t){return M(e,t,"local")},exports.useMatchMedia=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=d(o.useState(!1),2),r=n[0],u=n[1],c=o.useRef(null),i=function(e){return u(e.matches)},a=function(){return c.current&&c.current.removeEventListener("change",i)&&(c.current=null)};return o.useEffect((function(){return t&&(c.current=window.matchMedia(e),u(c.current.matches),c.current&&c.current.addEventListener("change",i)),a}),[e,t]),r},exports.useMergeProps=function(){var r=e.useContext(n.PrimeReactContext);return function(){for(var e=arguments.length,n=new Array(e),u=0;u<e;u++)n[u]=arguments[u];return t.mergeProps(n,null==r?void 0:r.ptOptions)}},exports.useMountEffect=S,exports.useMouse=function(){var e=d(o.useState({x:0,y:0}),2),t=e[0],n=e[1],r=o.useRef(null),u=o.useCallback((function(e){var t,u;if(r.current){var o=e.currentTarget.getBoundingClientRect();t=e.pageX-o.left-(window.pageXOffset||window.scrollX),u=e.pageY-o.top-(window.pageYOffset||window.scrollY)}else t=e.clientX,u=e.clientY;n({x:Math.max(0,Math.round(t)),y:Math.max(0,Math.round(u))})}),[]),c=d(y({target:r,type:"mousemove",listener:u}),2),i=c[0],a=c[1],l=d(y({type:"mousemove",listener:u}),2),s=l[0],f=l[1];return o.useEffect((function(){return i(),r.current||s(),function(){a(),r.current||f()}}),[s,i,f,a]),R(R({ref:r},t),{},{reset:function(){return n({x:0,y:0})}})},exports.useMove=function(e){var t=e.mode,n=void 0===t?"both":t,r=e.initialValue,u=void 0===r?{x:0,y:0}:r,c=d(o.useState(u),2),i=c[0],a=c[1],l=d(o.useState(!1),2),s=l[0],f=l[1],p=o.useRef(!1),v=o.useRef(!1),m=o.useRef(null),g=function(e){return z({x:e.clientX,y:e.clientY})},h=function(e){var t=e.clampedX,r=e.clampedY;"vertical"===n?a({y:1-r}):"horizontal"===n?a({x:t}):"both"===n&&a({x:t,y:r})},b=function(){v.current&&p.current&&(v.current=!1,f(!1),G())},w=function(e){e.cancelable&&e.preventDefault(),z({x:e.changedTouches[0].clientX,y:e.changedTouches[0].clientY})},E=d(y({type:"mousemove",listener:g}),2),O=E[0],S=E[1],x=d(y({type:"mouseup",listener:b}),2),D=x[0],j=x[1],P=d(y({type:"touchmove",listener:w}),2),L=P[0],R=P[1],I=d(y({type:"touchend",listener:b}),2),A=I[0],T=I[1],M=d(y({target:m,type:"mousedown",listener:function(e){X(),e.preventDefault(),g(e)}}),2),k=M[0],N=M[1],H=d(y({target:m,type:"touchstart",listener:function(e){e.cancelable&&e.preventDefault(),X(),w(e)},options:{passive:!1}}),2),_=H[0],K=H[1],Y=function(e,t,n){return Math.min(Math.max(e,t),n)},U=function(e){var t=e.y;return{clampedX:Y(e.x,0,1),clampedY:Y(t,0,1)}},G=function(){S(),j(),R(),T()};o.useEffect((function(){p.current=!0}),[]);var X=function(){!v.current&&p.current&&(v.current=!0,f(!0),O(),D(),L(),A())},z=function(e){var t=e.x,n=e.y;if(v.current){var r=m.current.getBoundingClientRect(),u=U({x:(t-r.left)/r.width,y:(n-r.top)/r.height});h({clampedX:u.clampedX,clampedY:u.clampedY})}};return o.useEffect((function(){return m.current&&(k(),_()),function(){m.current&&(N(),K())}}),[k,_,i,N,K]),C(C({ref:m},i),{},{active:s,reset:function(){a(u)}})},exports.useOverlayListener=function(e){var n=e.target,r=e.overlay,u=e.listener,c=e.when,i=void 0===c||c,a=e.type,l=void 0===a?"click":a,s=o.useRef(null),f=o.useRef(null),p=d(y({target:"window",type:l,listener:function(e){u&&u(e,{type:"outside",valid:3!==e.which&&P(e)})},when:i}),2),m=p[0],g=p[1],h=d(T({listener:function(e){u&&u(e,{type:"resize",valid:!t.DomHandler.isTouchDevice()})},when:i}),2),b=h[0],w=h[1],E=d(y({target:"window",type:"orientationchange",listener:function(e){u&&u(e,{type:"orientationchange",valid:!0})},when:i}),2),O=E[0],S=E[1],x=d(A({target:n,listener:function(e){u&&u(e,{type:"scroll",valid:!0})},when:i}),2),D=x[0],j=x[1],P=function(e){return s.current&&!(s.current.isSameNode(e.target)||s.current.contains(e.target)||f.current&&f.current.contains(e.target))},L=function(){g(),w(),S(),j()};return o.useEffect((function(){i?(s.current=t.DomHandler.getTargetElement(n),f.current=t.DomHandler.getTargetElement(r)):(L(),s.current=f.current=null)}),[n,r,i]),v((function(){L()})),[function(){m(),b(),O(),D()},L]},exports.useOverlayScrollListener=A,exports.usePrevious=p,exports.useResizeListener=T,exports.useSessionStorage=function(e,t){return M(e,t,"session")},exports.useStorage=M,exports.useStyle=function(r){var u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=d(e.useState(!1),2),i=o[0],a=o[1],l=e.useRef(null),s=e.useContext(n.PrimeReactContext),f=t.DomHandler.isClient()?window.document:void 0,p=u.document,v=void 0===p?f:p,y=u.manual,m=void 0!==y&&y,g=u.name,h=void 0===g?"style_".concat(++k):g,b=u.id,w=void 0===b?void 0:b,E=u.media,O=void 0===E?void 0:E,S=function(e){var t=e.querySelector('style[data-primereact-style-id="'.concat(h,'"]'));if(t)return t;if(void 0!==w){var n=v.getElementById(w);if(n)return n}return v.createElement("style")},x=function(){if(v&&!i){var e=(null==s?void 0:s.styleContainer)||v.head;l.current=S(e),l.current.isConnected||(l.current.type="text/css",w&&(l.current.id=w),O&&(l.current.media=O),t.DomHandler.addNonce(l.current,s&&s.nonce||c.default.nonce),e.appendChild(l.current),h&&l.current.setAttribute("data-primereact-style-id",h)),l.current.textContent=r,a(!0)}};return e.useEffect((function(){m||x()}),[m]),{id:w,name:h,update:function(e){i&&r!==e&&(l.current.textContent=e)},unload:function(){v&&l.current&&(t.DomHandler.removeInlineStyle(l.current),a(!1))},load:x,isLoaded:i}},exports.useTimeout=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=o.useRef(null),u=o.useRef(null),c=o.useCallback((function(){return clearTimeout(r.current)}),[r.current]);return o.useEffect((function(){u.current=e})),o.useEffect((function(){if(n)return r.current=setTimeout((function(){u.current()}),t),c;c()}),[t,n]),v((function(){c()})),[c]},exports.useUnmountEffect=v,exports.useUpdateEffect=function(e,t){var n=o.useRef(!1);return o.useEffect((function(){if(n.current)return e&&e();n.current=!0}),t)};