UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 4.05 kB
import{_ as e}from"../../chunks/tslib.es6.js";import{watch as s,initial as t}from"../../core/reactiveUtils.js";import{property as i}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import"../../core/arrayUtils.js";import{subclass as l}from"../../core/accessorSupport/decorators/subclass.js";import o from"../Slider.js";import"../support/widgetUtils.js";import{tsx as r}from"../support/jsxFactory.js";import n from"./ValuePickerBaseComponent.js";import a from"./ValuePickerSliderVisibleElements.js";const u="esri-value-picker__slider",p={minorTick:`${u}__tick-minor`,majorTick:`${u}__tick-major`,stepsTick:`${u}__tick-steps`};function c(e){return(s,t)=>{t.classList.add(e)}}let d=class extends n{constructor(e,s){super(e,s),this._majorTickCreatedFunction=c(p.majorTick),this._minorTickCreatedFunction=c(p.minorTick),this._stepsTickCreatedFunction=c(p.stepsTick),this._slider=new o({visibleElements:{labels:!0}}),this.labelFormatFunction=null,this.labels=null,this.min=null,this.minorTicks=null,this.majorTicks=null,this.max=null,this.reversed=!1,this.steps=null,this.type="slider",this.visibleElements=new a}initialize(){this.addHandles([s((()=>this.viewModel?.values),(e=>{this._slider.values=e}),t),s((()=>this._slider.values),(e=>{this.viewModel&&this.viewModel.values!==e&&(this.viewModel.values=e)}))])}destroy(){this._slider.destroy()}get _ascending(){const{reversed:e,viewModel:s}=this;if(!s)return null;const{layout:t}=s;return"horizontal"===t&&!e||"vertical"===t&&e}get canNext(){const{_ascending:e,min:s,max:t,steps:i,viewModel:l}=this;if(null==e||null==s||null==t||!i?.length||!l)return!1;const{values:o}=l,r=o?.[0];return null==r||(e?r!==i[i.length-1]:r!==i[0])}get canPlay(){return null!=this.viewModel&&!!this.steps?.length&&null!=this.min&&null!=this.max}get canPrevious(){const{_ascending:e,min:s,max:t,steps:i,viewModel:l}=this;if(null==e||null==s||null==t||!i?.length||!l)return!1;const{values:o}=l,r=o?.[0];return null==r||(e?r!==i[0]:r!==i[i.length-1])}render(){const{labels:e,labelFormatFunction:s,min:t,max:i,steps:l,minorTicks:o,majorTicks:n,reversed:a,viewModel:p}=this;if(!p)return r("div",null);const{disabled:c,layout:d}=p,h=`${d}${a?"-reversed":""}`,m="position",v=[],_={labels:this.visibleElements.thumbTooltip};return null!=t&&null!=i&&(o&&v.push({mode:m,values:o,tickCreatedFunction:this._minorTickCreatedFunction}),n&&v.push({mode:m,values:n,tickCreatedFunction:this._majorTickCreatedFunction}),e&&v.push({mode:m,values:e,labelsVisible:!0}),this.visibleElements.steps&&this.steps&&v.push({mode:m,values:this.steps,tickCreatedFunction:this._stepsTickCreatedFunction})),this._slider.set({disabled:c,labelFormatFunction:s,layout:h,min:t,max:i,steps:l,tickConfigs:v,visibleElements:_}),r("div",{class:u},this._slider.render())}animate(){this._step(this._ascending?1:-1)}next(){this._step(this._ascending?1:-1)}previous(){this._step(this._ascending?-1:1)}_step(e){if(!this.viewModel||!this.steps?.length)return;if(!this.viewModel.values||!this.steps.includes(this.viewModel.values[0]))return void(this.viewModel.values=[this.steps[0]]);const s=this.steps.indexOf(this.viewModel.values[0])+e;s<0||s>=this.steps.length?this.viewModel.loop?this.viewModel.values=[this.steps[1===e?0:this.steps.length-1]]:"playing"===this.viewModel.state&&this.viewModel.pause():this.viewModel.values=[this.steps[s]]}};e([i()],d.prototype,"_ascending",null),e([i()],d.prototype,"canNext",null),e([i()],d.prototype,"canPlay",null),e([i()],d.prototype,"canPrevious",null),e([i()],d.prototype,"labelFormatFunction",void 0),e([i()],d.prototype,"labels",void 0),e([i()],d.prototype,"min",void 0),e([i()],d.prototype,"minorTicks",void 0),e([i()],d.prototype,"majorTicks",void 0),e([i()],d.prototype,"max",void 0),e([i({nonNullable:!0})],d.prototype,"reversed",void 0),e([i()],d.prototype,"steps",void 0),e([i()],d.prototype,"type",void 0),e([i({type:a,nonNullable:!0})],d.prototype,"visibleElements",void 0),d=e([l("esri.widgets.ValuePicker.ValuePickerSlider")],d);const h=d;export{h as default};