2 lines
9.1 KiB
JavaScript
2 lines
9.1 KiB
JavaScript
this.primereact=this.primereact||{},this.primereact.slider=function(e,t,n){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=r(t);function s(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 o(e){if(Array.isArray(e))return s(e)}function a(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 s(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)?s(e,t):void 0}}function u(){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,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}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 d(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function c(e,t){return c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},c(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&&c(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 g(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 d(e)}function v(e){return v=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},v(e)}function y(){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,L,E,w=function(e){f(L,e);var t,r,s,c,m,b=(t=L,r=y(),function(){var e,n=v(t);if(r){var i=v(this).constructor;e=Reflect.construct(n,arguments,i)}else e=n.apply(this,arguments);return g(this,e)});function L(e){var t;return h(this,L),(t=b.call(this,e)).onBarClick=t.onBarClick.bind(d(t)),t.onKeyDown=t.onKeyDown.bind(d(t)),t.handleIndex=0,t}return s=L,(c=[{key:"value",get:function(){return this.props.range?this.props.value||[0,100]:this.props.value||0}},{key:"spin",value:function(e,t){this.updateValue(e,(this.props.range?this.value[this.handleIndex]:this.value)+(this.props.step||1)*t),e.preventDefault()}},{key:"onDragStart",value:function(e,t){this.props.disabled||(this.dragging=!0,this.updateDomData(),this.sliderHandleClick=!0,this.handleIndex=t)}},{key:"onMouseDown",value:function(e,t){this.bindDragListeners(),this.onDragStart(e,t)}},{key:"onTouchStart",value:function(e,t){this.bindTouchListeners(),this.onDragStart(e,t)}},{key:"onKeyDown",value:function(e,t){if(!this.props.disabled){this.handleIndex=t;var n=e.key;"ArrowRight"===n||"ArrowUp"===n?this.spin(e,1):"ArrowLeft"!==n&&"ArrowDown"!==n||this.spin(e,-1)}}},{key:"onBarClick",value:function(e){if(!this.props.disabled){if(!this.sliderHandleClick){this.updateDomData();var t=this.setValue(e);this.props.onSlideEnd&&this.props.onSlideEnd({originalEvent:e,value:t})}this.sliderHandleClick=!1}}},{key:"onDrag",value:function(e){this.dragging&&(this.setValue(e),e.preventDefault())}},{key:"onDragEnd",value:function(e){this.dragging&&(this.dragging=!1,this.props.onSlideEnd&&this.props.onSlideEnd({originalEvent:e,value:this.props.value}),this.unbindDragListeners(),this.unbindTouchListeners())}},{key:"bindDragListeners",value:function(){this.dragListener||(this.dragListener=this.onDrag.bind(this),document.addEventListener("mousemove",this.dragListener)),this.dragEndListener||(this.dragEndListener=this.onDragEnd.bind(this),document.addEventListener("mouseup",this.dragEndListener))}},{key:"unbindDragListeners",value:function(){this.dragListener&&(document.removeEventListener("mousemove",this.dragListener),this.dragListener=null),this.dragEndListener&&(document.removeEventListener("mouseup",this.dragEndListener),this.dragEndListener=null)}},{key:"bindTouchListeners",value:function(){this.dragListener||(this.dragListener=this.onDrag.bind(this),document.addEventListener("touchmove",this.dragListener)),this.dragEndListener||(this.dragEndListener=this.onDragEnd.bind(this),document.addEventListener("touchend",this.dragEndListener))}},{key:"unbindTouchListeners",value:function(){this.dragListener&&(document.removeEventListener("touchmove",this.dragListener),this.dragListener=null),this.dragEndListener&&(document.removeEventListener("touchend",this.dragEndListener),this.dragEndListener=null)}},{key:"updateDomData",value:function(){var e=this.el.getBoundingClientRect();this.initX=e.left+n.DomHandler.getWindowScrollLeft(),this.initY=e.top+n.DomHandler.getWindowScrollTop(),this.barWidth=this.el.offsetWidth,this.barHeight=this.el.offsetHeight}},{key:"setValue",value:function(e){var t=("horizontal"===this.props.orientation?100*((e.touches?e.touches[0].pageX:e.pageX)-this.initX)/this.barWidth:100*(this.initY+this.barHeight-(e.touches?e.touches[0].pageY:e.pageY))/this.barHeight)/100*(this.props.max-this.props.min)+this.props.min;if(this.props.step){var n=this.props.range?this.value[this.handleIndex]:this.value,r=t-n;r<0?t=n+Math.ceil(t/this.props.step-n/this.props.step)*this.props.step:r>0&&(t=n+Math.floor(t/this.props.step-n/this.props.step)*this.props.step)}else t=Math.floor(t);return this.updateValue(e,t)}},{key:"updateValue",value:function(e,t){var n,r=parseFloat(t.toFixed(10)),i=r;return this.props.range?(0===this.handleIndex?r<this.props.min?r=this.props.min:r>this.value[1]&&(r=this.value[1]):r>this.props.max?r=this.props.max:r<this.value[0]&&(r=this.value[0]),(i=o(n=this.value)||a(n)||l(n)||u())[this.handleIndex]=r,this.props.onChange&&this.props.onChange({originalEvent:e,value:i})):(r<this.props.min?r=this.props.min:r>this.props.max&&(r=this.props.max),i=r,this.props.onChange&&this.props.onChange({originalEvent:e,value:i})),i}},{key:"componentWillUnmount",value:function(){this.unbindDragListeners(),this.unbindTouchListeners()}},{key:"renderHandle",value:function(e,t,r){var s=this,o=n.classNames("p-slider-handle",{"p-slider-handle-start":0===r,"p-slider-handle-end":1===r,"p-slider-handle-active":this.handleIndex===r});return i.default.createElement("span",{onMouseDown:function(e){return s.onMouseDown(e,r)},onTouchStart:function(e){return s.onTouchStart(e,r)},onKeyDown:function(e){return s.onKeyDown(e,r)},tabIndex:this.props.tabIndex,className:o,style:{transition:this.dragging?"none":null,left:null!==e&&e+"%",bottom:t&&t+"%"},role:"slider","aria-valuemin":this.props.min,"aria-valuemax":this.props.max,"aria-valuenow":e||t,"aria-labelledby":this.props.ariaLabelledBy})}},{key:"renderRangeSlider",value:function(){var e=this.value,t="horizontal"===this.props.orientation,n=100*(e[0]<this.props.min?0:e[0]-this.props.min)/(this.props.max-this.props.min),r=100*(e[1]>this.props.max?100:e[1]-this.props.min)/(this.props.max-this.props.min),s=t?this.renderHandle(n,null,0):this.renderHandle(null,n,0),o=t?this.renderHandle(r,null,1):this.renderHandle(null,r,1);return i.default.createElement(i.default.Fragment,null,i.default.createElement("span",{className:"p-slider-range",style:t?{left:n+"%",width:r-n+"%"}:{bottom:n+"%",height:r-n+"%"}}),s,o)}},{key:"renderSingleSlider",value:function(){var e,t=this.value;e=t<this.props.min?0:t>this.props.max?100:100*(t-this.props.min)/(this.props.max-this.props.min);var n="horizontal"===this.props.orientation?{width:e+"%"}:{height:e+"%"},r="horizontal"===this.props.orientation?this.renderHandle(e,null,null):this.renderHandle(null,e,null);return i.default.createElement(i.default.Fragment,null,i.default.createElement("span",{className:"p-slider-range",style:n}),r)}},{key:"render",value:function(){var e=this,t=n.classNames("p-slider p-component",this.props.className,{"p-disabled":this.props.disabled,"p-slider-horizontal":"horizontal"===this.props.orientation,"p-slider-vertical":"vertical"===this.props.orientation}),r=this.props.range?this.renderRangeSlider():this.renderSingleSlider();return i.default.createElement("div",{id:this.props.id,ref:function(t){return e.el=t},style:this.props.style,className:t,onClick:this.onBarClick},r)}}])&&p(s.prototype,c),m&&p(s,m),Object.defineProperty(s,"prototype",{writable:!1}),L}(t.Component);return E={id:null,value:null,min:0,max:100,orientation:"horizontal",step:null,range:!1,style:null,className:null,disabled:!1,tabIndex:0,ariaLabelledBy:null,onChange:null,onSlideEnd:null},(L="defaultProps")in(b=w)?Object.defineProperty(b,L,{value:E,enumerable:!0,configurable:!0,writable:!0}):b[L]=E,e.Slider=w,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.utils);
|