@arcgis/coding-components
Version:
ArcGIS Coding Components
142 lines (141 loc) • 3.87 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { i as c, b as P } from "./utils.js";
import { CompletionItemKind as h, InsertTextFormat as g, InsertTextMode as F } from "vscode-languageserver-types";
import { f as b, L as w, E as x } from "./language-defaults-base.js";
import { fetchT9nStringsBundle as E } from "@arcgis/toolkit/intl";
import { g as M } from "./runtime.js";
const A = {
allowAllRootBinaryOperators: !1,
requiresPredicateRootNode: !1
}, d = {
"field-calculation": A,
"where-clause": {
allowAllRootBinaryOperators: !0,
requiresPredicateRootNode: !0,
allowGeometryFields: !0
}
};
function v(o) {
return o && o in d ? d[o] : void 0;
}
const q = (o) => {
const r = o.variables[0], t = r?.type === "featureSet" ? T(r) : void 0, { apiVersion: e, bundles: i, hiddenApiItems: s } = o.toEditorProfileDefinition();
return {
apiVersion: e,
bundles: i,
variables: t ? [t] : [],
hiddenApiItems: s?.map((a) => a.toLowerCase())
};
};
function T(o) {
const { name: r } = o, t = o.getDescription(), { definition: e } = o.toProfileVariableDefinition(), i = {
label: r,
detail: r,
insertText: r,
insertTextMode: F.asIs,
insertTextFormat: g.PlainText,
kind: h.Field
}, s = {
name: r,
description: t,
type: "dictionary",
properties: [],
completion: i
};
if (!e || !("fields" in e))
return s;
const [a, l] = b(e.fields, t, {
includeAliases: !1,
supportGeometryFields: !0
});
return s.properties = a, i.documentation = { kind: "markdown", value: l }, s;
}
const u = [
{
name: "$layer",
type: "featureSet",
description: "The layer being calculated."
}
], D = {
"field-calculation": {
id: "field-calculation",
variables: u
},
"where-clause": {
id: "where-clause",
variables: u
}
};
function L(o) {
return D[o] ?? null;
}
function S(o) {
if (!c(o))
return;
const r = L(
o.id
/*locale*/
);
if (!r)
return;
const t = {
variables: [],
hiddenApiItems: o.hiddenApiItems?.map((e) => e.toLowerCase())
};
return r.variables.forEach((e) => {
if (o.disabledVariables?.includes(e.name))
return;
const i = o.definitions[e.name];
if (e.type === "featureSet")
return P(i) ? t.variables.push({ ...e, type: e.type, definition: i }) : void 0;
throw Error(`sdkVariable type not supported (yet) type: ${e.type}`);
}), t;
}
const f = "arcgis-sql-expression";
class _ extends w {
constructor() {
super(f, {
apiPath: "./assets/sql-language/api",
apiPrefix: "sql-api.t9n."
}), this._languageId = f, this._layerMap = /* @__PURE__ */ new Map();
}
// TODO: try to rely on editor profile instance instead of storing a feature layer
updateFeatureLayerForModel(r, t) {
const e = this._getApiKey(r);
this._layerMap.set(e, t);
}
getFeatureLayerForModel(r) {
const t = this._getApiKey(r);
return this._layerMap.get(t);
}
async setProfileForModel(r, t, e = { locale: "en" }) {
const i = c(t) ? v(t.id) : void 0;
c(t) && (t = S(t));
const s = await E(
e.locale,
M("./assets/editor-profile/t9n"),
"messages."
);
if (!s)
throw new Error(`Failed to load the language bundle for ${e.locale}`);
this.disposeForModel(r);
const a = this._getApiKey(r), l = new x(t, s, e.locale, i);
this._modelToProfileMap.set(a, l);
const y = q(l);
this.updateApiContextForModel(r, {
locale: e.locale,
profile: y,
...i ? { profilePolicy: i } : {}
});
const p = t?.variables?.find((m) => m.name === "$layer");
p && this.updateFeatureLayerForModel(r, p.definition);
}
}
const n = new _(), $ = {
setProfileForModel: n.setProfileForModel.bind(n),
getApiLibraryForModel: n.getApiLibraryForModel.bind(n)
};
export {
n as a,
$ as s
};