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) • 16.9 kB
JavaScript
this.primereact=this.primereact||{},this.primereact.hooks=function(e,t,n,r){"use strict";function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function o(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=o(t),i=u(r);function a(e){if(Array.isArray(e))return e}function l(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 f(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 f(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)?f(e,t):void 0}}function d(){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 v(e,t){return a(e)||l(e,t)||s(e,t)||d()}var y=function(e){var t=c.useRef(null);return c.useEffect((function(){return t.current=e,function(){t.current=null}}),[e]),t.current},m=function(e){return c.useEffect((function(){return e}),[])},p=function(e){var t=e.target,r=void 0===t?"document":t,u=e.type,o=e.listener,i=e.options,a=e.when,l=void 0===a||a,f=c.useRef(null),s=c.useRef(null),d=y(o),v=y(i),p=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.target;n.ObjectUtils.isNotEmpty(t)&&(g(),(e.when||l)&&(f.current=n.DomHandler.getTargetElement(t))),!s.current&&f.current&&(s.current=function(e){return o&&o(e)},f.current.addEventListener(u,s.current,i))},g=function(){s.current&&(f.current.removeEventListener(u,s.current,i),s.current=null)},h=function(){g(),d=null,v=null},b=c.useCallback((function(){l?f.current=n.DomHandler.getTargetElement(r):(g(),f.current=null)}),[r,l]);return c.useEffect((function(){b()}),[b]),c.useEffect((function(){var e="".concat(d)!=="".concat(o),t=s.current;t&&(e||v!==i)?(g(),l&&p()):t||h()}),[o,i,l]),m((function(){h()})),[p,g]},g={},h={ico:"image/x-icon",png:"image/png",svg:"image/svg+xml",gif:"image/gif"};function b(e){if(Array.isArray(e))return f(e)}function w(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function E(){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 O(e){return b(e)||w(e)||s(e)||E()}var S={escKeyListeners:new Map,onGlobalKeyDown:function(e){if("Escape"===e.code){var t=S.escKeyListeners,n=Math.max.apply(Math,O(t.keys())),r=t.get(n),u=Math.max.apply(Math,O(r.keys()));r.get(u)(e)}},refreshGlobalKeyDownListener:function(){var e=n.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=v(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()}}},D=function(e){var t=c.useRef(!1);return c.useEffect((function(){if(!t.current)return t.current=!0,e&&e()}),[])};function j(e){return j="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},j(e)}function P(e,t){if("object"!=j(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=j(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function R(e){var t=P(e,"string");return"symbol"==j(t)?t:t+""}function L(e,t,n){return(t=R(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function x(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 I(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?x(Object(n),!0).forEach((function(t){L(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):x(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function C(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 A(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?C(Object(n),!0).forEach((function(t){L(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):C(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var T=function(e){var t=e.target,u=e.listener,o=e.options,a=e.when,l=void 0===a||a,f=c.useContext(r.PrimeReactContext),s=c.useRef(null),d=c.useRef(null),v=c.useRef([]),p=y(u),g=y(o),h=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(n.ObjectUtils.isNotEmpty(e.target)&&(b(),(e.when||l)&&(s.current=n.DomHandler.getTargetElement(e.target))),!d.current&&s.current){var t=f?f.hideOverlaysOnDocumentScrolling:i.default.hideOverlaysOnDocumentScrolling,r=v.current=n.DomHandler.getScrollableParents(s.current);r.some((function(e){return e===document.body||e===window}))||r.push(t?window:document.body),d.current=function(e){return u&&u(e)},r.forEach((function(e){return e.addEventListener("scroll",d.current,o)}))}},b=function(){d.current&&(v.current.forEach((function(e){return e.removeEventListener("scroll",d.current,o)})),d.current=null)},w=function(){b(),v.current=null,p=null,g=null},E=c.useCallback((function(){l?s.current=n.DomHandler.getTargetElement(t):(b(),s.current=null)}),[t,l]);return c.useEffect((function(){E()}),[E]),c.useEffect((function(){var e="".concat(p)!=="".concat(u),t=d.current;t&&(e||g!==o)?(b(),l&&h()):t||w()}),[u,o,l]),m((function(){w()})),[h,b]},M=function(e){var t=e.when;return p({target:"window",type:"resize",listener:e.listener,when:void 0===t||t})},k=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"local",r="undefined"!=typeof window,u=v(p({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;f(u)}}}),2),o=u[0],i=u[1],a=v(c.useState(e),2),l=a[0],f=a[1];return c.useEffect((function(){r||f(e);try{var u="local"===n?window.localStorage.getItem(t):window.sessionStorage.getItem(t);f(u?JSON.parse(u):e)}catch(t){f(e)}return o(),function(){return i()}}),[]),[l,function(e){try{var u=e instanceof Function?e(l):e;if(f(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))}}]},N=0;return e.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},e.useClickOutside=function(e,t){var n=function(n){e.current&&!e.current.contains(n.target)&&t(n)},r=v(p({type:"mousedown",listener:n}),2),u=r[0],o=r[1],i=v(p({type:"touchstart",listener:n}),2),a=i[0],l=i[1];return c.useEffect((function(){if(e.current)return u(),a(),function(){o(),l()}})),[e,t]},e.useCounter=function(){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{step:1},t=v(c.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)}}},e.useDebounce=function(e,t){var n=v(c.useState(e),2),r=n[0],u=n[1],o=v(c.useState(e),2),i=o[0],a=o[1],l=c.useRef(!1),f=c.useRef(null),s=function(){return window.clearTimeout(f.current)};return D((function(){l.current=!0})),m((function(){s()})),c.useEffect((function(){l.current&&(s(),f.current=window.setTimeout((function(){a(r)}),t))}),[r,t]),[r,i,u]},e.useDisplayOrder=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=v(c.useState((function(){return n.UniqueComponentId()})),1)[0],u=v(c.useState(0),2),o=u[0],i=u[1];return c.useEffect((function(){if(t){g[e]||(g[e]=[]);var u=g[e].push(r);return i(u),function(){delete g[e][u-1];var t=g[e].length-1,r=n.ObjectUtils.findLastIndex(g[e],(function(e){return void 0!==e}));r!==t&&g[e].splice(r+1),i(void 0)}}}),[e,r,t]),o},e.useEventListener=p,e.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";c.useLayoutEffect((function(){if(e){document.querySelectorAll("link[rel*='icon']").forEach((function(e){document.head.removeChild(e)}));var n=document.createElement("link");n.setAttribute("type",h[e.split(".").pop()]),n.setAttribute("rel",t),n.setAttribute("href",e),document.head.appendChild(n)}}),[e,t])},e.useGlobalOnEscapeKey=function(e){var n=e.callback,r=e.when,u=e.priority;t.useEffect((function(){if(r)return S.addListener(n,u)}),[n,r,u])},e.useIntersectionObserver=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=v(c.useState(!1),2),r=n[0],u=n[1];return c.useEffect((function(){if(e.current){var n=new IntersectionObserver((function(e){var t=v(e,1);u(t[0].isIntersecting)}),t);return n.observe(e.current),function(){n.disconnect()}}}),[t,e]),r},e.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=c.useRef(null),u=c.useRef(null),o=c.useCallback((function(){return clearInterval(r.current)}),[r.current]);return c.useEffect((function(){u.current=e})),c.useEffect((function(){if(n)return r.current=setInterval((function(){u.current()}),t),o;o()}),[t,n]),m((function(){o()})),[o]},e.useLocalStorage=function(e,t){return k(e,t,"local")},e.useMatchMedia=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=v(c.useState(!1),2),r=n[0],u=n[1],o=c.useRef(null),i=function(e){return u(e.matches)},a=function(){return o.current&&o.current.removeEventListener("change",i)&&(o.current=null)};return c.useEffect((function(){return t&&(o.current=window.matchMedia(e),u(o.current.matches),o.current&&o.current.addEventListener("change",i)),a}),[e,t]),r},e.useMergeProps=function(){var e=t.useContext(r.PrimeReactContext);return function(){for(var t=arguments.length,r=new Array(t),u=0;u<t;u++)r[u]=arguments[u];return n.mergeProps(r,null==e?void 0:e.ptOptions)}},e.useMountEffect=D,e.useMouse=function(){var e=v(c.useState({x:0,y:0}),2),t=e[0],n=e[1],r=c.useRef(null),u=c.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))})}),[]),o=v(p({target:r,type:"mousemove",listener:u}),2),i=o[0],a=o[1],l=v(p({type:"mousemove",listener:u}),2),f=l[0],s=l[1];return c.useEffect((function(){return i(),r.current||f(),function(){a(),r.current||s()}}),[f,i,s,a]),I(I({ref:r},t),{},{reset:function(){return n({x:0,y:0})}})},e.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,o=v(c.useState(u),2),i=o[0],a=o[1],l=v(c.useState(!1),2),f=l[0],s=l[1],d=c.useRef(!1),y=c.useRef(!1),m=c.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(){y.current&&d.current&&(y.current=!1,s(!1),G())},w=function(e){e.cancelable&&e.preventDefault(),z({x:e.changedTouches[0].clientX,y:e.changedTouches[0].clientY})},E=v(p({type:"mousemove",listener:g}),2),O=E[0],S=E[1],D=v(p({type:"mouseup",listener:b}),2),j=D[0],P=D[1],R=v(p({type:"touchmove",listener:w}),2),L=R[0],x=R[1],I=v(p({type:"touchend",listener:b}),2),C=I[0],T=I[1],M=v(p({target:m,type:"mousedown",listener:function(e){X(),e.preventDefault(),g(e)}}),2),k=M[0],N=M[1],H=v(p({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(),P(),x(),T()};c.useEffect((function(){d.current=!0}),[]);var X=function(){!y.current&&d.current&&(y.current=!0,s(!0),O(),j(),L(),C())},z=function(e){var t=e.x,n=e.y;if(y.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 c.useEffect((function(){return m.current&&(k(),_()),function(){m.current&&(N(),K())}}),[k,_,i,N,K]),A(A({ref:m},i),{},{active:f,reset:function(){a(u)}})},e.useOverlayListener=function(e){var t=e.target,r=e.overlay,u=e.listener,o=e.when,i=void 0===o||o,a=e.type,l=void 0===a?"click":a,f=c.useRef(null),s=c.useRef(null),d=v(p({target:"window",type:l,listener:function(e){u&&u(e,{type:"outside",valid:3!==e.which&&R(e)})},when:i}),2),y=d[0],g=d[1],h=v(M({listener:function(e){u&&u(e,{type:"resize",valid:!n.DomHandler.isTouchDevice()})},when:i}),2),b=h[0],w=h[1],E=v(p({target:"window",type:"orientationchange",listener:function(e){u&&u(e,{type:"orientationchange",valid:!0})},when:i}),2),O=E[0],S=E[1],D=v(T({target:t,listener:function(e){u&&u(e,{type:"scroll",valid:!0})},when:i}),2),j=D[0],P=D[1],R=function(e){return f.current&&!(f.current.isSameNode(e.target)||f.current.contains(e.target)||s.current&&s.current.contains(e.target))},L=function(){g(),w(),S(),P()};return c.useEffect((function(){i?(f.current=n.DomHandler.getTargetElement(t),s.current=n.DomHandler.getTargetElement(r)):(L(),f.current=s.current=null)}),[t,r,i]),m((function(){L()})),[function(){y(),b(),O(),j()},L]},e.useOverlayScrollListener=T,e.usePrevious=y,e.useResizeListener=M,e.useSessionStorage=function(e,t){return k(e,t,"session")},e.useStorage=k,e.useStyle=function(e){var u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=v(t.useState(!1),2),c=o[0],a=o[1],l=t.useRef(null),f=t.useContext(r.PrimeReactContext),s=n.DomHandler.isClient()?window.document:void 0,d=u.document,y=void 0===d?s:d,m=u.manual,p=void 0!==m&&m,g=u.name,h=void 0===g?"style_".concat(++N):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=y.getElementById(w);if(n)return n}return y.createElement("style")},D=function(){if(y&&!c){var t=(null==f?void 0:f.styleContainer)||y.head;l.current=S(t),l.current.isConnected||(l.current.type="text/css",w&&(l.current.id=w),O&&(l.current.media=O),n.DomHandler.addNonce(l.current,f&&f.nonce||i.default.nonce),t.appendChild(l.current),h&&l.current.setAttribute("data-primereact-style-id",h)),l.current.textContent=e,a(!0)}};return t.useEffect((function(){p||D()}),[p]),{id:w,name:h,update:function(t){c&&e!==t&&(l.current.textContent=t)},unload:function(){y&&l.current&&(n.DomHandler.removeInlineStyle(l.current),a(!1))},load:D,isLoaded:c}},e.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=c.useRef(null),u=c.useRef(null),o=c.useCallback((function(){return clearTimeout(r.current)}),[r.current]);return c.useEffect((function(){u.current=e})),c.useEffect((function(){if(n)return r.current=setTimeout((function(){u.current()}),t),o;o()}),[t,n]),m((function(){o()})),[o]},e.useUnmountEffect=m,e.useUpdateEffect=function(e,t){var n=c.useRef(!1);return c.useEffect((function(){if(n.current)return e&&e();n.current=!0}),t)},Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.utils,primereact.api);