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