UNPKG

@arcgis/coding-components

Version:
2 lines 3.06 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */ export default $arcgis.t(([u,{property:d,subclass:v}])=>{var I=Object.defineProperty,y=Object.getOwnPropertyDescriptor,r=(t,e,s,i)=>{for(var a=i>1?void 0:i?y(e,s):e,h=t.length-1,l;h>=0;h--)(l=t[h])&&(a=(i?l(e,s,a):l(a))||a);return i&&a&&I(e,s,a),a},b="scope";function c(t){return`preview:${t}`}function p(t){let e=t.split(".").filter(Boolean).at(-1)??t;return e.length>12?`${e.slice(0,12)}...`:e}var o=class extends u{constructor(t){super(t),this.fields=[],this.id="",this.invalidated=!1,this.label="",this.message="",this.requestId=0,this.rows=[],this.sourcePath="",this.status="idle",this.title=""}};r([d()],o.prototype,"fields",2);r([d()],o.prototype,"id",2);r([d()],o.prototype,"invalidated",2);r([d()],o.prototype,"label",2);r([d()],o.prototype,"message",2);r([d()],o.prototype,"requestId",2);r([d()],o.prototype,"rows",2);r([d()],o.prototype,"sourcePath",2);r([d()],o.prototype,"status",2);r([d()],o.prototype,"title",2);o=r([v("ArcadeDebuggerPreviewTabState")],o);var n=class extends u{constructor(t){super(t),this.activeTabId=b,this.tabs=[],this.revision=0,this.tabsById=new Map}get activeTab(){return this.tabsById.get(this.activeTabId)}clear(){this.revision+=1,this.activeTabId=b,this.destroyTabs()}closeTab(t){let e=this.tabs.findIndex(h=>h.id===t);if(e<0)return;let s=this.activeTabId===t,i=this.tabs[e+1]??this.tabs[e-1],a=this.tabs[e];this.tabsById.delete(t),a.destroy(),this.tabs=this.tabs.filter(h=>h.id!==t),s&&(this.activeTabId=i?.id??b)}getOrCreateTab(t,e){let s=c(t),i=this.tabsById.get(s);if(i)return i.label=t,i.sourcePath=e,i.title=p(t),i;let a=new o;return a.id=s,a.label=t,a.sourcePath=e,a.title=p(t),this.tabsById.set(s,a),this.tabs=[...this.tabs,a],a}getTab(t){return this.tabsById.get(t)}invalidateAll(){this.revision+=1,this.activeTabId=b;for(let t of this.tabs)t.invalidated=!0,this.resetTab(t)}isTabLoading(t){return this.tabsById.get(c(t))?.status==="loading"}selectScope(){this.activeTabId=b}selectTab(t){if(t===b){this.selectScope();return}this.tabsById.has(t)&&(this.activeTabId=t)}startLoad(t,e){let s=this.getOrCreateTab(t,e),i=s.requestId+1;return s.requestId=i,s.invalidated=!1,this.resetTab(s),s.status="loading",this.activeTabId=s.id,{snapshot:{revision:this.revision,requestId:i,tabId:s.id},tab:s}}setError(t,e){let s=this.validateSnapshot(t);s&&(s.status="error",s.message=e)}setLoaded(t,e,s){let i=this.validateSnapshot(t);i&&(i.status="loaded",i.message="",i.fields=e,i.rows=s)}setUnavailable(t,e){let s=this.validateSnapshot(t);s&&(s.status="unavailable",s.message=e,s.fields=[],s.rows=[])}destroyTabs(){for(let t of this.tabsById.values())t.destroy();this.tabsById.clear(),this.tabs=[]}resetTab(t){t.status="idle",t.message="",t.fields=[],t.rows=[]}validateSnapshot(t){let e=this.tabsById.get(t.tabId);if(!(!e||this.revision!==t.revision||e.requestId!==t.requestId))return e}};r([d()],n.prototype,"activeTabId",2);r([d()],n.prototype,"tabs",2);n=r([v("ArcadeDebuggerPreviewTabsState")],n);return{a:b,b:n}},"core/Accessor","core/accessorSupport/decorators")