UNPKG

@arcgis/coding-components

Version:

Contains components for editing code in different languages. The currently supported languages are html, css, json, TypeScript, JavaScript, and Arcade.

53 lines (52 loc) 2.38 kB
import { html as b } from "lit"; /*! All material copyright Esri, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. v4.33.14 */ const m = [ "popup", "popup-element", "visualization", "labeling", "aggregate-field", "popup-feature-reduction", "popup-voxel" ], w = (e) => { const s = m.includes(e); return s || console.warn(`Profile "${e}" is not supported by the Arcade Coding Assistant.`), s; }, A = (e) => { const { aiAssistantsEnabled: s } = e; return s === void 0 ? (console.warn("areAiAssistantsEnabled is not defined in the organizations settings."), !1) : !!s; }, v = () => typeof globalThis < "u" && "$arcgis" in globalThis && typeof globalThis.$arcgis == "object" && "import" in globalThis.$arcgis && !("forceESM" in globalThis.$arcgis), T = async (e) => v() ? (await (await globalThis.$arcgis.import("@arcgis/core/identity/IdentityManager.js")).getCredential(e))?.token || "" : (await (await import("@arcgis/core/identity/IdentityManager.js")).default.getCredential(e)).token || ""; async function E({ portalUrl: e, profileId: s, feedbackServiceUrl: n, appVersion: o, panelName: r }) { if (!customElements.get("arcgis-arcade-coding-assistant")) throw new Error("arcgis-arcade-coding-assistant component is not registered. Please ensure the component is imported from @arcgis/coding-components."); const i = await T(e), c = `${e}/sharing/rest/portals/self?f=json&token=${i}`, l = `${e}/sharing/rest/portals/self/settings?f=json&token=${i}`, [a, d] = await Promise.all([ fetch(c, { credentials: "include" }).then((t) => t.json()), fetch(l, { credentials: "include" }).then((t) => t.json()) ]), g = a?.helperServices?.aiAssistantServices?.url, p = a.helpBase, u = A(d); return { enabled: w(s), id: "arcade-assistant", name: r, icon: "effects", useFlows: !0, location: "sidebar", renderer: ({ closePanel: t, insertText: f, closed: h, editorRef: $ }) => b` <arcgis-arcade-coding-assistant .portalUrl=${e} .serviceUrl=${g} .feedbackServiceUrl=${n} .closePanel=${t} .insertText=${f} .closed=${h} .editorRef=${$} .appVersion=${o} .helpBase=${p} ?assistants-enabled=${u} ></arcgis-arcade-coding-assistant> ` }; } export { E as useArcadeAssistant };