2 lines
10 KiB
JavaScript
2 lines
10 KiB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(e);function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function s(e){if(Array.isArray(e))return i(e)}function o(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function l(e,t){if(e){if("string"==typeof e)return i(e,t);var n=Object.prototype.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)?i(e,t):void 0}}function a(){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 u(e){return s(e)||o(e)||l(e)||a()}function p(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function h(e,t,n){return t&&p(e.prototype,t),n&&p(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function c(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function d(e,t){return d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},d(e,t)}function f(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&d(e,t)}function m(e){return m="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},m(e)}function v(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function y(e,t){if(t&&("object"===m(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return v(e)}function g(e){return g=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},g(e)}function S(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function z(e){var t=E();return function(){var n,r=g(e);if(t){var i=g(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return y(this,n)}}function E(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}var b=function(t){f(r,e.Component);var n=z(r);function r(){return c(this,r),n.apply(this,arguments)}return h(r)}();S(b,"defaultProps",{size:null,minSize:null,style:null,className:null});var w=function(n){f(s,e.Component);var i=z(s);function s(){return c(this,s),i.apply(this,arguments)}return h(s,[{key:"bindMouseListeners",value:function(){var e=this;this.mouseMoveListener||(this.mouseMoveListener=function(t){return e.onResize(t)},document.addEventListener("mousemove",this.mouseMoveListener)),this.mouseUpListener||(this.mouseUpListener=function(t){e.onResizeEnd(t),e.unbindMouseListeners()},document.addEventListener("mouseup",this.mouseUpListener))}},{key:"validateResize",value:function(e,t){return!(this.props.children[this.prevPanelIndex].props&&this.props.children[this.prevPanelIndex].props.minSize&&this.props.children[this.prevPanelIndex].props.minSize>e)&&!(this.props.children[this.prevPanelIndex+1].props&&this.props.children[this.prevPanelIndex+1].props.minSize&&this.props.children[this.prevPanelIndex+1].props.minSize>t)}},{key:"unbindMouseListeners",value:function(){this.mouseMoveListener&&(document.removeEventListener("mousemove",this.mouseMoveListener),this.mouseMoveListener=null),this.mouseUpListener&&(document.removeEventListener("mouseup",this.mouseUpListener),this.mouseUpListener=null)}},{key:"clear",value:function(){this.dragging=!1,this.size=null,this.startPos=null,this.prevPanelElement=null,this.nextPanelElement=null,this.prevPanelSize=null,this.nextPanelSize=null,this.gutterElement=null,this.prevPanelIndex=null}},{key:"isStateful",value:function(){return null!=this.props.stateKey}},{key:"getStorage",value:function(){switch(this.props.stateStorage){case"local":return window.localStorage;case"session":return window.sessionStorage;default:throw new Error(this.props.stateStorage+' is not a valid value for the state storage, supported values are "local" and "session".')}}},{key:"saveState",value:function(){this.getStorage().setItem(this.props.stateKey,JSON.stringify(this.panelSizes))}},{key:"restoreState",value:function(){var e=this,n=this.getStorage().getItem(this.props.stateKey);return!!n&&(this.panelSizes=JSON.parse(n),u(this.container.children).filter((function(e){return t.DomHandler.hasClass(e,"p-splitter-panel")})).forEach((function(t,n){t.style.flexBasis="calc("+e.panelSizes[n]+"% - "+(e.props.children.length-1)*e.props.gutterSize+"px)"})),!0)}},{key:"onResizeStart",value:function(e,n){var r="touchstart"===e.type?e.touches[0].pageX:e.pageX,i="touchstart"===e.type?e.touches[0].pageY:e.pageY;this.gutterElement=e.currentTarget,this.size="horizontal"===this.props.layout?t.DomHandler.getWidth(this.container):t.DomHandler.getHeight(this.container),this.dragging=!0,this.startPos="horizontal"===this.props.layout?r:i,this.prevPanelElement=this.gutterElement.previousElementSibling,this.nextPanelElement=this.gutterElement.nextElementSibling,this.prevPanelSize=100*("horizontal"===this.props.layout?t.DomHandler.getOuterWidth(this.prevPanelElement,!0):t.DomHandler.getOuterHeight(this.prevPanelElement,!0))/this.size,this.nextPanelSize=100*("horizontal"===this.props.layout?t.DomHandler.getOuterWidth(this.nextPanelElement,!0):t.DomHandler.getOuterHeight(this.nextPanelElement,!0))/this.size,this.prevPanelIndex=n,t.DomHandler.addClass(this.gutterElement,"p-splitter-gutter-resizing"),t.DomHandler.addClass(this.container,"p-splitter-resizing")}},{key:"onResize",value:function(e){var t,n=this.prevPanelSize+(t="horizontal"===this.props.layout?100*("touchmove"===e.type?e.touches[0].pageX:e.pageX)/this.size-100*this.startPos/this.size:100*("touchmove"===e.type?e.touches[0].pageY:e.pageY)/this.size-100*this.startPos/this.size),r=this.nextPanelSize-t;this.validateResize(n,r)&&(this.prevPanelElement.style.flexBasis="calc("+n+"% - "+(this.props.children.length-1)*this.props.gutterSize+"px)",this.nextPanelElement.style.flexBasis="calc("+r+"% - "+(this.props.children.length-1)*this.props.gutterSize+"px)",this.panelSizes[this.prevPanelIndex]=n,this.panelSizes[this.prevPanelIndex+1]=r)}},{key:"onResizeEnd",value:function(e){this.isStateful()&&this.saveState(),this.props.onResizeEnd&&this.props.onResizeEnd({originalEvent:e,sizes:this.panelSizes}),t.DomHandler.removeClass(this.gutterElement,"p-splitter-gutter-resizing"),t.DomHandler.removeClass(this.container,"p-splitter-resizing"),this.clear()}},{key:"onGutterMouseDown",value:function(e,t){this.onResizeStart(e,t),this.bindMouseListeners()}},{key:"onGutterTouchStart",value:function(e,t){this.onResizeStart(e,t),this.windowTouchMoveListener=this.onGutterTouchMove.bind(this),this.windowTouchEndListener=this.onGutterTouchEnd.bind(this),window.addEventListener("touchmove",this.windowTouchMoveListener,{passive:!1,cancelable:!1}),window.addEventListener("touchend",this.windowTouchEndListener)}},{key:"onGutterTouchMove",value:function(e){this.onResize(e)}},{key:"onGutterTouchEnd",value:function(e){this.onResizeEnd(e),window.removeEventListener("touchmove",this.windowTouchMoveListener),window.removeEventListener("touchend",this.windowTouchEndListener),this.windowTouchMoveListener=null,this.windowTouchEndListener=null}},{key:"componentDidMount",value:function(){var e=this;if(this.panelElement&&this.panelElement.childNodes&&t.ObjectUtils.isNotEmpty(t.DomHandler.find(this.panelElement,".p-splitter"))&&t.DomHandler.addClass(this.panelElement,"p-splitter-panel-nested"),this.props.children&&this.props.children.length){var n=!1;if(this.isStateful()&&(n=this.restoreState()),!n){var r=u(this.container.children).filter((function(e){return t.DomHandler.hasClass(e,"p-splitter-panel")})),i=[];this.props.children.map((function(t,n){var s=(t.props&&t.props.size?t.props.size:null)||100/e.props.children.length;return i[n]=s,r[n].style.flexBasis="calc("+s+"% - "+(e.props.children.length-1)*e.props.gutterSize+"px)",i})),this.panelSizes=i}}}},{key:"renderPanel",value:function(e,n){var i=this,s=t.classNames("p-splitter-panel",e.props.className),o=n!==this.props.children.length-1&&r.default.createElement("div",{ref:function(e){return i.gutterElement=e},className:"p-splitter-gutter",style:"horizontal"===this.props.layout?{width:this.props.gutterSize+"px"}:{height:this.props.gutterSize+"px"},onMouseDown:function(e){return i.onGutterMouseDown(e,n)},onTouchStart:function(e){return i.onGutterTouchStart(e,n)},onTouchMove:function(e){return i.onGutterTouchMove(e)},onTouchEnd:function(e){return i.onGutterTouchEnd(e)}},r.default.createElement("div",{className:"p-splitter-gutter-handle"}));return r.default.createElement(r.default.Fragment,null,r.default.createElement("div",{ref:function(e){return i.panelElement=e},key:n,className:s,style:e.props.style},e.props.children),o)}},{key:"renderPanels",value:function(){var e=this;return r.default.Children.map(this.props.children,(function(t,n){return e.renderPanel(t,n)}))}},{key:"render",value:function(){var e=this,n=t.classNames("p-splitter p-component p-splitter-".concat(this.props.layout),this.props.className),i=this.renderPanels();return r.default.createElement("div",{ref:function(t){return e.container=t},id:this.props.id,className:n,style:this.props.style},i)}}]),s}();S(w,"defaultProps",{id:null,className:null,style:null,layout:"horizontal",gutterSize:4,stateKey:null,stateStorage:"session",onResizeEnd:null}),exports.Splitter=w,exports.SplitterPanel=b;
|