Spinner.js 2.2 KB

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