Spinner.js 2.3 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{_ as i}from"../chunks/tslib.es6.js";import{isNone as e}from"../core/maybe.js";import{after as t}from"../core/promiseUtils.js";import{watch as s}from"../core/reactiveUtils.js";import{property as o}from"../core/accessorSupport/decorators/property.js";import"../core/arrayUtils.js";import"../core/accessorSupport/ensureType.js";import{subclass as r}from"../core/accessorSupport/decorators/subclass.js";import n from"./Widget.js";import l from"./Spinner/SpinnerViewModel.js";import"./support/widgetUtils.js";import{tsx as a}from"./support/jsxFactory.js";const p={base:"esri-spinner",spinnerStart:"esri-spinner--start",spinnerFinish:"esri-spinner--finish"};let c=class extends n{constructor(i,e){super(i,e),this._animationDelay=500,this._animationPromise=null,this.viewModel=new l}initialize(){this.addHandles(s((()=>this.visible),(i=>this._visibleChange(i))))}destroy(){this._animationPromise=null}get location(){return this.viewModel.location}set location(i){this.viewModel.location=i}get view(){return this.viewModel.view}set view(i){this.viewModel.view=i}get visible(){return this.viewModel.visible}set visible(i){this.viewModel.visible=i}show(i){const{location:e,promise:t}=i;e&&(this.viewModel.location=e),this.visible=!0;const s=()=>this.hide();t&&t.catch((()=>{})).then(s)}hide(){this.visible=!1}render(){const{visible:i}=this,{screenLocation:e}=this.viewModel,t=!!e,s=i&&t,o=!i&&t,r={[p.spinnerStart]:s,[p.spinnerFinish]:o},n=this._getPositionStyles();return a("div",{class:this.classes(p.base,r),styles:n})}_visibleChange(i){if(i)return void(this.viewModel.screenLocationEnabled=!0);const e=t(this._animationDelay);this._animationPromise=e,e.catch((()=>{})).then((()=>{this._animationPromise===e&&(this.viewModel.screenLocationEnabled=!1,this._animationPromise=null)}))}_getPositionStyles(){const{screenLocation:i,view:t}=this.viewModel;if(e(t)||e(i))return{};const{padding:s}=t;return{left:i.x-s.left+"px",top:i.y-s.top+"px"}}};i([o()],c.prototype,"location",null),i([o()],c.prototype,"view",null),i([o({type:l})],c.prototype,"viewModel",void 0),i([o()],c.prototype,"visible",null),c=i([r("esri.widgets.Spinner")],c);const h=c;export{h as default};