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) 7.93 kB
this.primereact=this.primereact||{},this.primereact.splitter=function(e,t,r,n){"use strict";function u(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var l=u(t);function o(){return o=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},o.apply(this,arguments)}function i(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function a(e){if(Array.isArray(e))return c(e)}function s(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function p(e,t){if(e){if("string"==typeof e)return c(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?c(e,t):void 0}}function f(){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 d(e){throw new TypeError('"'+e+'" is read-only')}function m(e){if(Array.isArray(e))return e}function h(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,u,l=[],o=!0,i=!1;try{for(r=r.call(e);!(o=(n=r.next()).done)&&(l.push(n.value),!t||l.length!==t);o=!0);}catch(e){i=!0,u=e}finally{try{o||null==r.return||r.return()}finally{if(i)throw u}}return l}}function y(){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 g(e,t){return m(e)||h(e,t)||p(e,t)||y()}function v(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function b(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?v(Object(r),!0).forEach((function(t){i(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):v(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var O=function(){},S=l.memo(l.forwardRef((function(e,t){var u=l.useRef(null),i=l.useRef(),c=l.useRef({}),m=l.useRef(null),h=l.useRef(null),y=l.useRef(null),v=l.useRef(null),w=l.useRef(null),E=l.useRef(null),z=l.useRef(null),j=l.useRef(null),P=l.useRef(null),D=l.useRef(null),R=g(l.useState([]),2),H=R[0],N=R[1],x=null!=e.stateKey,C=e.children&&e.children.length,A=function(t,r){return r in t?t[r]:(e.children[r].props.size||100)/C},I=g(r.useEventListener({type:"mousemove",listener:function(e){return J(e)}}),2),T=I[0],_=I[1],K=g(r.useEventListener({type:"mouseup",listener:function(e){F(e),Y()}}),2),k=K[0],L=K[1],Y=function(){_(),L()},M=function(t,r){return!(t>100||t<0)&&(!(r>100||r<0)&&(!(e.children[D.current].props&&e.children[D.current].props.minSize&&e.children[D.current].props.minSize>t)&&!(e.children[D.current+1].props&&e.children[D.current+1].props.minSize&&e.children[D.current+1].props.minSize>r)))},U=l.useCallback((function(){switch(e.stateStorage){case"local":return window.localStorage;case"session":return window.sessionStorage;default:throw new Error(e.stateStorage+' is not a valid value for the state storage, supported values are "local" and "session".')}}),[e.stateStorage]),X=function(t){U().setItem(e.stateKey,JSON.stringify(t))},B=l.useCallback((function(){var t=U().getItem(e.stateKey);t&&N(JSON.parse(t))}),[U,e.stateKey]),W=function(t,r){i.current=c.current[r];var l="touchstart"===t.type?t.touches[0].pageX:t.pageX,o="touchstart"===t.type?t.touches[0].pageY:t.pageY;m.current="horizontal"===e.layout?n.DomHandler.getWidth(u.current):n.DomHandler.getHeight(u.current),h.current=!0,y.current="horizontal"===e.layout?l:o,v.current=i.current.previousElementSibling,w.current=i.current.nextElementSibling,E.current=100*("horizontal"===e.layout?n.DomHandler.getOuterWidth(v.current,!0):n.DomHandler.getOuterHeight(v.current,!0))/m.current,z.current=E.current,j.current=100*("horizontal"===e.layout?n.DomHandler.getOuterWidth(w.current,!0):n.DomHandler.getOuterHeight(w.current,!0))/m.current,P.current=j.current,D.current=r,n.DomHandler.addClass(i.current,"p-splitter-gutter-resizing"),n.DomHandler.addClass(u.current,"p-splitter-resizing")},J=function(t){var r,n=E.current+(r="horizontal"===e.layout?100*("touchmove"===t.type?t.touches[0].pageX:t.pageX)/m.current-100*y.current/m.current:100*("touchmove"===t.type?t.touches[0].pageY:t.pageY)/m.current-100*y.current/m.current),u=j.current-r;M(n,u)&&(z.current=n,P.current=u,v.current.style.flexBasis="calc("+n+"% - "+(e.children.length-1)*e.gutterSize+"px)",w.current.style.flexBasis="calc("+u+"% - "+(e.children.length-1)*e.gutterSize+"px)")},F=function(t){N((function(r){for(var n=[];0<e.children.length;d("index"))n[0]=A(r,0);return n[D.current]=z.current,n[D.current+1]=P.current,e.onResizeEnd&&e.onResizeEnd({originalEvent:t,sizes:n}),x&&X(n),n})),n.DomHandler.removeClass(i.current,"p-splitter-gutter-resizing"),n.DomHandler.removeClass(u.current,"p-splitter-resizing"),h.current=!1,m.current=null,y.current=null,v.current=null,w.current=null,E.current=null,z.current=null,j.current=null,P.current=null,D.current=null},$=function(e,t){W(e,t),T(),k()},q=function(e,t){W(e,t),window.addEventListener("touchmove",G,{passive:!1,cancelable:!1}),window.addEventListener("touchend",Q)},G=function(e){J(e)},Q=function e(t){F(t),window.removeEventListener("touchmove",G),window.removeEventListener("touchend",e)};l.useImperativeHandle(t,(function(){return{props:e,getElement:function(){return u.current}}})),l.useEffect((function(){var e;(e=u.current.children,a(e)||s(e)||p(e)||f()).filter((function(e){return n.DomHandler.hasClass(e,"p-splitter-panel")})).map((function(e){e.childNodes&&n.ObjectUtils.isNotEmpty(n.DomHandler.find(e,".p-splitter"))&&n.DomHandler.addClass(e,"p-splitter-panel-nested")}))}),[]),l.useEffect((function(){x&&B()}),[B,x]);var V=function(t,r){var u=n.ObjectUtils.findDiffKeys(t.props,O.defaultProps),i=n.classNames("p-splitter-panel",t.props.className),a=r!==e.children.length-1&&l.createElement("div",{ref:function(e){return c.current[r]=e},className:"p-splitter-gutter",style:"horizontal"===e.layout?{width:e.gutterSize+"px"}:{height:e.gutterSize+"px"},onMouseDown:function(e){return $(e,r)},onTouchStart:function(e){return q(e,r)},onTouchMove:function(e){return G(e)},onTouchEnd:function(e){return Q(e)}},l.createElement("div",{className:"p-splitter-gutter-handle"})),s="calc("+A(H,r)+"% - "+(C-1)*e.gutterSize+"px)";return l.createElement(l.Fragment,null,l.createElement("div",o({key:r,className:i,style:b(b({},t.props.style),{},{flexBasis:s})},u),t.props.children),a)},Z=n.ObjectUtils.findDiffKeys(e,S.defaultProps),ee=n.classNames("p-splitter p-component p-splitter-".concat(e.layout),e.className),te=l.Children.map(e.children,V);return l.createElement("div",o({ref:u,id:e.id,className:ee,style:e.style},Z),te)})));return O.displayName="SplitterPanel",O.defaultProps={__TYPE:"SplitterPanel",className:null,minSize:null,size:null,style:null},S.displayName="Splitter",S.defaultProps={__TYPE:"Splitter",className:null,gutterSize:4,id:null,layout:"horizontal",onResizeEnd:null,stateKey:null,stateStorage:"session",style:null},e.Splitter=S,e.SplitterPanel=O,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.hooks,primereact.utils);