@arcgis/coding-components
Version:
ArcGIS Coding Components
179 lines (178 loc) • 4.91 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import p from "@arcgis/core/core/Accessor.js";
import { property as d, subclass as v } from "/core/core/accessorSupport/decorators.js";
var f = Object.defineProperty, g = Object.getOwnPropertyDescriptor, r = (t, s, e, i) => {
for (var a = i > 1 ? void 0 : i ? g(s, e) : s, n = t.length - 1, c; n >= 0; n--)
(c = t[n]) && (a = (i ? c(s, e, a) : c(a)) || a);
return i && a && f(s, e, a), a;
};
const b = "scope";
function l(t) {
return `preview:${t}`;
}
function u(t) {
const e = t.split(".").filter(Boolean).at(-1) ?? t;
return e.length > 12 ? `${e.slice(0, 12)}...` : e;
}
let o = class extends p {
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);
let h = class extends p {
constructor(t) {
super(t), this.activeTabId = b, this.tabs = [], this.revision = 0, this.tabsById = /* @__PURE__ */ new Map();
}
/**
* The active tab's state.
*/
get activeTab() {
return this.tabsById.get(this.activeTabId);
}
/**
* Clears all preview tabs and resets to the default state with only the scope tab available.
*/
clear() {
this.revision += 1, this.activeTabId = b, this.destroyTabs();
}
/**
* Closes a specific tab by id.
* If the closed tab is active, the first adjacent tab will be activated.
*/
closeTab(t) {
const s = this.tabs.findIndex((n) => n.id === t);
if (s < 0)
return;
const e = this.activeTabId === t, i = this.tabs[s + 1] ?? this.tabs[s - 1], a = this.tabs[s];
this.tabsById.delete(t), a.destroy(), this.tabs = this.tabs.filter((n) => n.id !== t), e && (this.activeTabId = i?.id ?? b);
}
/**
* Ensures a preview tab exists for the given label and source path, creating it if necessary, and returns the tab state.
*/
getOrCreateTab(t, s) {
const e = l(t), i = this.tabsById.get(e);
if (i)
return i.label = t, i.sourcePath = s, i.title = u(t), i;
const a = new o();
return a.id = e, a.label = t, a.sourcePath = s, a.title = u(t), this.tabsById.set(e, a), this.tabs = [...this.tabs, a], a;
}
/**
* Returns the tab state for a given tab id.
*/
getTab(t) {
return this.tabsById.get(t);
}
/**
* Invalidates all tabs.
* This is used to mark all existing preview data as stale.
*/
invalidateAll() {
this.revision += 1, this.activeTabId = b;
for (const t of this.tabs)
t.invalidated = !0, this.resetTab(t);
}
isTabLoading(t) {
return this.tabsById.get(l(t))?.status === "loading";
}
/**
* Selects the scope tab, which is the default tab that shows variable scopes when debugging.
*/
selectScope() {
this.activeTabId = b;
}
/**
* Selects a specific tab by id, if it exists. If the scope tab id is provided, selects the scope tab instead.
*/
selectTab(t) {
if (t === b) {
this.selectScope();
return;
}
this.tabsById.has(t) && (this.activeTabId = t);
}
/**
* Starts loading data for a specific preview tab.
*/
startLoad(t, s) {
const e = this.getOrCreateTab(t, s), i = e.requestId + 1;
return e.requestId = i, e.invalidated = !1, this.resetTab(e), e.status = "loading", this.activeTabId = e.id, {
snapshot: {
revision: this.revision,
requestId: i,
tabId: e.id
},
tab: e
};
}
setError(t, s) {
const e = this.validateSnapshot(t);
e && (e.status = "error", e.message = s);
}
setLoaded(t, s, e) {
const i = this.validateSnapshot(t);
i && (i.status = "loaded", i.message = "", i.fields = s, i.rows = e);
}
setUnavailable(t, s) {
const e = this.validateSnapshot(t);
e && (e.status = "unavailable", e.message = s, e.fields = [], e.rows = []);
}
destroyTabs() {
for (const 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) {
const s = this.tabsById.get(t.tabId);
if (!(!s || this.revision !== t.revision || s.requestId !== t.requestId))
return s;
}
};
r([
d()
], h.prototype, "activeTabId", 2);
r([
d()
], h.prototype, "tabs", 2);
h = r([
v("ArcadeDebuggerPreviewTabsState")
], h);
export {
h as A,
b as d
};