@arcgis/coding-components
Version:
ArcGIS Coding Components
283 lines (282 loc) • 11.8 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { html as c } from "lit";
import { safeClassMap as R } from "@arcgis/lumina";
import { t as v } from "./debugger-value-styles.js";
import { quoteString as O } from "@arcgis/toolkit/string";
const U = /^[$A-Z_a-z][$\w]*$/u;
function M(e) {
return e.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
}
function H(e) {
return U.test(e);
}
function B(e) {
return typeof e == "number" ? `[${e}]` : e.startsWith("name:") ? `[name="${M(e.slice(5))}"]` : e.startsWith("id:") ? `[id="${M(e.slice(3))}"]` : H(e) ? `.${e}` : `["${M(e)}"]`;
}
function A(e, t) {
if (e[t] !== '"')
return;
let n = "", r = t + 1;
for (; r < e.length; ) {
const p = e[r];
if (p === "\\") {
if (r += 1, r >= e.length)
return;
n += e[r], r += 1;
continue;
}
if (p === '"')
return {
value: n,
nextIndex: r + 1
};
n += p, r += 1;
}
}
function J(e) {
if (!e)
return;
let t = 0;
const n = [];
for (; t < e.length && /[$A-Z_a-z0-9]/u.test(e[t]); )
t += 1;
const r = e.slice(0, t);
if (!r)
return;
for (; t < e.length; ) {
const f = e[t];
if (f === ".") {
t += 1;
const o = t;
for (; t < e.length && /[$\w]/u.test(e[t]); )
t += 1;
if (o === t)
return;
n.push(e.slice(o, t));
continue;
}
if (f !== "[")
return;
if (t += 1, /\d/u.test(e[t] ?? "")) {
const o = t;
for (; t < e.length && /\d/u.test(e[t]); )
t += 1;
if (e[t] !== "]")
return;
n.push(e.slice(o, t)), t += 1;
continue;
}
const $ = e.startsWith("name=", t) ? "name" : e.startsWith("id=", t) ? "id" : void 0;
if ($) {
const o = A(e, t + $.length + 1);
if (!o || e[o.nextIndex] !== "]")
return;
n.push(`${$}:${o.value}`), t = o.nextIndex + 1;
continue;
}
const s = A(e, t);
if (!s || e[s.nextIndex] !== "]")
return;
n.push(s.value), t = s.nextIndex + 1;
}
const [p, ...a] = n;
if (p)
return {
scopeName: r,
rootName: p,
pathSegments: a
};
}
function de(e, t) {
return `${e}${B(t)}`;
}
function k(e, t) {
return e ? `${e}.${t}` : String(t);
}
function q(e, t) {
if (e)
return `${e}${B(t)}`;
}
function fe(e) {
return J(e);
}
function E(e, t) {
return typeof t == "number" ? `${e}[${t}]` : `${e}.${t}`;
}
function K(e) {
return e.name ? `name:${e.name}` : `id:${e.id}`;
}
function X(e) {
return Object.entries(e).filter(([t]) => t !== "featureSet");
}
function Y(e, t) {
if (t) {
const n = t.featureSet;
return {
kind: "feature-set",
displayValue: n.arcadeType,
featureSetValue: n,
loadRequest: { kind: "schema", load: () => n.schema() },
mergedCollectionItem: t
};
}
return e.type === "feature-set" ? {
kind: "feature-set",
displayValue: e.arcadeType,
featureSetValue: e,
loadRequest: { kind: "schema", load: () => e.schema() }
} : e.type === "feature-set-collection" ? {
kind: "collection",
collectionValue: e,
displayValue: e.arcadeType,
loadRequest: { kind: "collection", load: () => e.load() }
} : null;
}
function C(e) {
return c`<calcite-tree slot=children .lines=${v.lines} .selectionMode=${v.selectionMode} .scale=${v.scale} @calciteTreeSelect=${v.oncalciteTreeSelect}>${e}</calcite-tree>`;
}
function G({ lazyTreeState: e, nodePath: t, mergedCollectionItem: n, expanded: r = !1, isMetadata: p = !1, messages: a, name: f, value: $, loadPreview: s, previewLabel: o, previewSourcePath: h, previewLoading: g = !1 }) {
const u = Y($, n);
if (!u)
return null;
const i = e.ensureNode(t, r, u.loadRequest), b = u.kind === "feature-set" ? u.featureSetValue : void 0, S = o ?? String(f), m = h ?? t, D = !!(s && S && b && typeof b.querySample == "function"), d = (l) => {
l.target === l.currentTarget && e.setExpanded(t, !0, u.loadRequest);
}, y = (l) => {
l.target === l.currentTarget && e.setExpanded(t, !1, u.loadRequest);
}, V = (l) => {
l.stopPropagation(), !(!s || !S || !b) && s({
label: S,
sourcePath: m,
value: b
});
}, w = () => c`<calcite-tree-item disabled><div class="tree-item-label"><span class="constant-value">${i.errorMessage || (a.loaderror ?? "Unable to load data.")}</span></div></calcite-tree-item>`, W = () => u.kind !== "feature-set" || !i.schemaValue ? null : x({ name: "schema", value: i.schemaValue, messages: a, path: E(t, "schema"), lazyTreeState: e }), Q = () => u.kind !== "feature-set" || !u.mergedCollectionItem ? [] : X(u.mergedCollectionItem).map(([l, I]) => x({ name: l, value: z(I), messages: a, path: E(t, l), lazyTreeState: e })), Z = () => {
if (u.kind !== "feature-set")
return null;
if (!i.expanded || i.status === "loading")
return C();
const l = [];
if (i.status === "error")
l.push(w());
else {
l.push(...Q());
const I = W();
I && l.push(I);
}
return l.length ? C(l) : C();
}, _ = () => u.kind !== "collection" ? null : !i.expanded || i.status === "loading" ? C() : C(c`${i.status === "error" ? w() : null}${i.status === "loaded" ? i.collectionItems.map((l) => G({ name: l.name || l.id, mergedCollectionItem: l, messages: a, nodePath: E(t, l.id), lazyTreeState: e, value: l.featureSet, loadPreview: s, previewLabel: k(o, l.name || l.id), previewSourcePath: q(m, K(l)), previewLoading: g })) : null}`), j = () => u.kind === "collection" ? _() : Z();
return c`<calcite-tree-item .expanded=${i.expanded} @calciteTreeItemExpand=${d} @calciteTreeItemCollapse=${y}><div class="tree-item-label">${T({ name: f, isMetadata: p })}<bdi>${u.displayValue}</bdi></div>${i.status === "loading" ? c`<calcite-loader slot=actions-end scale=s inline type=indeterminate .label=${a.loading ?? "Loading"} .text=${a.loading ?? "Loading"}></calcite-loader>` : null}${D ? c`<calcite-action slot=actions-end scale=s class="load-action" .text=${a.loadpreview ?? "Load preview"} text-enabled icon=play .disabled=${g} @click=${V}></calcite-action>` : null}${j()}</calcite-tree-item>`;
}
function z(e) {
if (e == null)
return { type: "primitive", arcadeType: "", value: null };
switch (typeof e) {
case "boolean":
return { type: "primitive", arcadeType: "Boolean", value: e };
case "number":
return { type: "primitive", arcadeType: "Number", value: e };
case "string":
return { type: "primitive", arcadeType: "String", value: e };
default:
return { type: "primitive", arcadeType: "String", value: String(e) };
}
}
const N = "tree-item-metadata";
function T({ name: e, isMetadata: t = !1 }) {
const n = t ? `dictionary-property ${N}` : "dictionary-property", r = t ? N : void 0;
return c`<bdi class=${R(n)}>${e}</bdi><bdi class=${R(r)}>: </bdi>`;
}
function P({ lazyTreeState: e, path: t, expanded: n = !1, value: r, subtree: p, messages: a, onLoadPreview: f, previewLabel: $, previewSourcePath: s, previewLoading: o = !1 }) {
const h = (d) => c`<calcite-tree slot=${"children"} .lines=${v.lines} .selectionMode=${v.selectionMode} .scale=${v.scale} @calciteTreeSelect=${v.oncalciteTreeSelect}>${d}</calcite-tree>`;
if (!n)
return h();
const g = e.ensureNode(t, n), u = (d) => g.visibleChildCount >= d ? null : c`<calcite-tree-item @click=${(V) => {
V.stopPropagation(), e.showMore(t, d);
}}><div class="tree-item-label"><span class=${R(N)}>${a.showmore ?? "Show more"}</span></div></calcite-tree-item>`, i = r.expand();
if (Array.isArray(i)) {
const d = i.slice(0, g.visibleChildCount), y = L(r) ? r.length : i.length;
return h(c`${d.map((V, w) => x({ name: w, value: V, messages: a, path: `${t}[${w}]`, lazyTreeState: e, onLoadPreview: f, previewLabel: k($, w), previewSourcePath: q(s, w), previewLoading: o }))}${u(i.length)}${x({ name: "length", value: { arcadeType: "Number", type: "primitive", value: y }, isMetadata: !0, messages: a, path: `${t}.length`, lazyTreeState: e })}`);
}
const b = r.arcadeType === "Feature" ? i.get("Geometry()") : void 0, S = Math.min(g.visibleChildCount, b ? i.size - 1 : i.size), m = [];
for (const [d, y] of i.entries())
if (!(d === "Geometry()" && r.arcadeType === "Feature")) {
if (m.length >= S)
break;
m.push([d, y]);
}
const D = !!(b && g.visibleChildCount > m.length);
return h(c`${m.map(([d, y]) => x({ name: d, value: y, messages: a, path: `${t}.${d}`, lazyTreeState: e, onLoadPreview: f, previewLabel: k($, d), previewSourcePath: q(s, d), previewLoading: o }))}${D ? x({ name: "geometry", value: b, messages: a, path: `${t}.geometry`, lazyTreeState: e, onLoadPreview: f, previewLabel: k($, "geometry"), previewSourcePath: q(s, "geometry"), previewLoading: o }) : null}${u(i.size)}`);
}
function ee(e) {
return "expand" in e;
}
function te(e) {
return e.type === "simple";
}
function re(e) {
return e.type === "primitive";
}
function L(e) {
return e.type === "sequence-container";
}
function ne(e) {
return e.type === "feature-set";
}
function ie(e) {
return e.type === "feature-set-collection";
}
function le(e) {
return e.type === "minimal";
}
function ae(e) {
return ne(e) || ie(e);
}
function x({ lazyTreeState: e, path: t, name: n, value: r, messages: p, expanded: a, isMetadata: f = !1, onLoadPreview: $, previewLabel: s, previewSourcePath: o, previewLoading: h = !1 }) {
if (r === void 0)
return null;
if (r === null)
return c`<calcite-tree-item .expanded=${a}><div class="tree-item-label">${T({ name: n, isMetadata: f })}<bdi class="uninitialized-value tree-item-metadata">${p.uninitialized ?? "uninitialized"}</bdi></div></calcite-tree-item>`;
if (ee(r)) {
const g = e.ensureNode(t, a), u = (m) => {
m.target === m.currentTarget && e.setExpanded(t, !0);
}, i = (m) => {
m.target === m.currentTarget && e.setExpanded(t, !1);
}, b = typeof r.arcadeType == "string" ? r.arcadeType : "unknown", S = L(r) ? `${b}(${r.length})` : b;
return c`<calcite-tree-item .expanded=${g.expanded} @calciteTreeItemExpand=${u} @calciteTreeItemCollapse=${i}><div class="tree-item-label">${T({ name: n, isMetadata: f })}<bdi>${S}</bdi></div>${P({ expanded: g.expanded, value: r, subtree: !0, messages: p, path: t, lazyTreeState: e, onLoadPreview: $, previewLabel: s, previewSourcePath: o, previewLoading: h })}</calcite-tree-item>`;
}
return ae(r) ? G({ name: n, value: r, nodePath: t, lazyTreeState: e, messages: p, expanded: a, isMetadata: f, loadPreview: $, previewLabel: s, previewSourcePath: o, previewLoading: h }) : te(r) ? c`<calcite-tree-item .expanded=${a}><div class="tree-item-label">${T({ name: n, isMetadata: f })}${F({ value: r })}</div></calcite-tree-item>` : re(r) || le(r) ? c`<calcite-tree-item .expanded=${a}><div class="tree-item-label">${T({ name: n, isMetadata: f })}${F({ value: r })}</div></calcite-tree-item>` : null;
}
const F = ({ value: e }) => {
switch (e.type) {
case "primitive":
if (e.value === null)
return c`<bdi class="constant-value">null</bdi>`;
switch (e.arcadeType) {
case "String":
return c`<bdi class="string-value">${O(String(e.value))}</bdi>`;
case "Number":
return c`<bdi class="number-value">${String(e.value)}</bdi>`;
case "Boolean":
return c`<bdi class="constant-value">${String(e.value)}</bdi>`;
default:
return null;
}
case "simple":
return c`<bdi class="date-value">${e.render()}</bdi>`;
case "minimal":
return c`<bdi class="constant-value">${e.arcadeType}</bdi>`;
default:
return null;
}
};
export {
x as D,
F as S,
ie as a,
ne as b,
re as c,
te as d,
de as e,
le as f,
ee as i,
fe as p
};