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.89 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/hooks"),r=require("primereact/utils");function n(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 u=n(e);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 o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(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 c(e){if(Array.isArray(e))return i(e)}function a(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function s(e,t){if(e){if("string"==typeof e)return i(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)?i(e,t):void 0}}function p(){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 f(e){throw new TypeError('"'+e+'" is read-only')}function d(e){if(Array.isArray(e))return e}function m(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 h(e,t){return d(e)||m(e,t)||s(e,t)||y()}function g(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 v(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?g(Object(r),!0).forEach((function(t){o(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):g(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var b=function(){},O=u.memo(u.forwardRef((function(e,n){var o=u.useRef(null),i=u.useRef(),d=u.useRef({}),m=u.useRef(null),y=u.useRef(null),g=u.useRef(null),S=u.useRef(null),w=u.useRef(null),E=u.useRef(null),z=u.useRef(null),j=u.useRef(null),P=u.useRef(null),D=u.useRef(null),H=h(u.useState([]),2),R=H[0],N=H[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=h(t.useEventListener({type:"mousemove",listener:function(e){return W(e)}}),2),T=I[0],_=I[1],K=h(t.useEventListener({type:"mouseup",listener:function(e){J(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=u.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))},q=u.useCallback((function(){var t=U().getItem(e.stateKey);t&&N(JSON.parse(t))}),[U,e.stateKey]),B=function(t,n){i.current=d.current[n];var u="touchstart"===t.type?t.touches[0].pageX:t.pageX,l="touchstart"===t.type?t.touches[0].pageY:t.pageY;m.current="horizontal"===e.layout?r.DomHandler.getWidth(o.current):r.DomHandler.getHeight(o.current),y.current=!0,g.current="horizontal"===e.layout?u:l,S.current=i.current.previousElementSibling,w.current=i.current.nextElementSibling,E.current=100*("horizontal"===e.layout?r.DomHandler.getOuterWidth(S.current,!0):r.DomHandler.getOuterHeight(S.current,!0))/m.current,z.current=E.current,j.current=100*("horizontal"===e.layout?r.DomHandler.getOuterWidth(w.current,!0):r.DomHandler.getOuterHeight(w.current,!0))/m.current,P.current=j.current,D.current=n,r.DomHandler.addClass(i.current,"p-splitter-gutter-resizing"),r.DomHandler.addClass(o.current,"p-splitter-resizing")},W=function(t){var r,n=E.current+(r="horizontal"===e.layout?100*("touchmove"===t.type?t.touches[0].pageX:t.pageX)/m.current-100*g.current/m.current:100*("touchmove"===t.type?t.touches[0].pageY:t.pageY)/m.current-100*g.current/m.current),u=j.current-r;M(n,u)&&(z.current=n,P.current=u,S.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)")},J=function(t){N((function(r){for(var n=[];0<e.children.length;f("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})),r.DomHandler.removeClass(i.current,"p-splitter-gutter-resizing"),r.DomHandler.removeClass(o.current,"p-splitter-resizing"),y.current=!1,m.current=null,g.current=null,S.current=null,w.current=null,E.current=null,z.current=null,j.current=null,P.current=null,D.current=null},F=function(e,t){B(e,t),T(),k()},$=function(e,t){B(e,t),window.addEventListener("touchmove",G,{passive:!1,cancelable:!1}),window.addEventListener("touchend",Q)},G=function(e){W(e)},Q=function e(t){J(t),window.removeEventListener("touchmove",G),window.removeEventListener("touchend",e)};u.useImperativeHandle(n,(function(){return{props:e,getElement:function(){return o.current}}})),u.useEffect((function(){var e;(e=o.current.children,c(e)||a(e)||s(e)||p()).filter((function(e){return r.DomHandler.hasClass(e,"p-splitter-panel")})).map((function(e){e.childNodes&&r.ObjectUtils.isNotEmpty(r.DomHandler.find(e,".p-splitter"))&&r.DomHandler.addClass(e,"p-splitter-panel-nested")}))}),[]),u.useEffect((function(){x&&q()}),[q,x]);var V=function(t,n){var o=r.ObjectUtils.findDiffKeys(t.props,b.defaultProps),i=r.classNames("p-splitter-panel",t.props.className),c=n!==e.children.length-1&&u.createElement("div",{ref:function(e){return d.current[n]=e},className:"p-splitter-gutter",style:"horizontal"===e.layout?{width:e.gutterSize+"px"}:{height:e.gutterSize+"px"},onMouseDown:function(e){return F(e,n)},onTouchStart:function(e){return $(e,n)},onTouchMove:function(e){return G(e)},onTouchEnd:function(e){return Q(e)}},u.createElement("div",{className:"p-splitter-gutter-handle"})),a="calc("+A(R,n)+"% - "+(C-1)*e.gutterSize+"px)";return u.createElement(u.Fragment,null,u.createElement("div",l({key:n,className:i,style:v(v({},t.props.style),{},{flexBasis:a})},o),t.props.children),c)},Z=r.ObjectUtils.findDiffKeys(e,O.defaultProps),ee=r.classNames("p-splitter p-component p-splitter-".concat(e.layout),e.className),te=u.Children.map(e.children,V);return u.createElement("div",l({ref:o,id:e.id,className:ee,style:e.style},Z),te)})));b.displayName="SplitterPanel",b.defaultProps={__TYPE:"SplitterPanel",className:null,minSize:null,size:null,style:null},O.displayName="Splitter",O.defaultProps={__TYPE:"Splitter",className:null,gutterSize:4,id:null,layout:"horizontal",onResizeEnd:null,stateKey:null,stateStorage:"session",style:null},exports.Splitter=O,exports.SplitterPanel=b;