@arcgis/coding-components
Version:
Contains components for editing code in different languages. The currently supported languages are html, css, json, TypeScript, JavaScript, and Arcade.
120 lines (119 loc) • 3.42 kB
JavaScript
import { f as u, i as c, a as y, L as m, E as g } from "./language-defaults-base.js";
import { InsertTextMode as h, InsertTextFormat as P, CompletionItemKind as F } from "vscode-languageserver-types";
import { fetchT9nStringsBundle as M } from "@arcgis/components-utils";
import { g as b } from "./runtime.js";
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
v4.32.13 */
const x = (r) => {
const e = r.variables[0], i = e && e.type === "featureSet" ? A(e) : void 0, { apiVersion: t, bundles: o, hiddenApiItems: s } = r.toEditorProfileDefinition();
return {
apiVersion: t,
bundles: o,
variables: i ? [i] : [],
hiddenApiItems: s?.map((a) => a.toLowerCase())
};
};
function A(r) {
const { name: e } = r, i = r.getDescription(), { definition: t } = r.toProfileVariableDefinition(), o = {
label: e,
detail: e,
insertText: e,
insertTextMode: h.asIs,
insertTextFormat: P.PlainText,
kind: F.Field
}, s = {
name: e,
description: i,
type: "dictionary",
properties: [],
completion: o
};
if (!t || !("fields" in t))
return s;
const [a, l] = u(t.fields, i);
return s.properties = a, o.documentation = { kind: "markdown", value: l }, s;
}
const T = {
id: "field-calculation",
variables: [
{
name: "$layer",
type: "featureSet",
description: "The layer being calculated."
}
]
};
function v() {
return T;
}
function E(r) {
if (!c(r))
return;
const e = v(
/*locale*/
);
if (!e)
return;
const i = {
variables: [],
hiddenApiItems: r.hiddenApiItems?.map((t) => t.toLowerCase())
};
return e.variables.forEach((t) => {
if (r.disabledVariables?.includes(t.name))
return;
const o = r.definitions[t.name];
switch (t.type) {
case "featureSet":
return y(o) ? i.variables.push({ ...t, type: t.type, definition: o }) : void 0;
default:
throw Error(`sdkVariable type not supported (yet) type: ${t.type}`);
}
}), i;
}
const d = "arcgis-sql-expression";
class w extends m {
constructor() {
super(d, {
apiPath: "./assets/sql-language/api",
apiPrefix: "sql-api.t9n."
}), this._languageId = d, this._layerMap = /* @__PURE__ */ new Map();
}
// TODO: try to rely on editor profile instance instead of storing a feature layer
updateFeatureLayerForModel(e, i) {
const t = this._getApiKey(e);
this._layerMap.set(t, i);
}
getFeatureLayerForModel(e) {
const i = this._getApiKey(e);
return this._layerMap.get(i);
}
async setProfileForModel(e, i, t = { locale: "en" }) {
c(i) && (i = E(i));
const o = await M(
t.locale,
b("./assets/editor-profile/t9n"),
"messages."
);
if (!o)
throw new Error(`Failed to load the language bundle for ${t.locale}`);
this.disposeForModel(e);
const s = this._getApiKey(e), a = new g(i, o);
this._modelToProfileMap.set(s, a);
const l = x(a);
this.updateApiContextForModel(e, {
locale: t.locale,
profile: l
});
const p = i?.variables?.find((f) => f.name === "$layer");
p && this.updateFeatureLayerForModel(e, p.definition);
}
}
const n = new w(), q = {
setProfileForModel: n.setProfileForModel.bind(n),
getApiLibraryForModel: n.getApiLibraryForModel.bind(n)
};
export {
n as a,
q as s
};