@arcgis/coding-components
Version:
Contains components for editing code in different languages. The currently supported languages are html, css, json, TypeScript, JavaScript, and Arcade.
137 lines (136 loc) • 6.83 kB
JavaScript
import { c as o } from "../../chunks/runtime.js";
import { ref as c } from "lit-html/directives/ref.js";
import { html as s } from "lit";
import { LitElement as n, createEvent as a } from "@arcgis/lumina";
import { setFocusOnElement as d, createFilterExpression as h } from "@arcgis/components-utils";
import { u as f } from "../../chunks/useT9n.js";
import { css as m } from "@lit/reactive-element/css-tag.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 u = m`:host{background-color:var(--calcite-color-foreground-1);.notice-container{margin:var(--calcite-spacing-xxs);padding:var(--calcite-spacing-sm);background-color:var(--calcite-color-foreground-1)}.sticky{position:sticky;top:0;z-index:10}calcite-flow{height:100%}calcite-list-item-group{background-color:var(--calcite-color-foreground-2)}}`;
function g(l) {
l.key === "Enter" && l.stopPropagation();
}
class p extends n {
constructor() {
super(...arguments), this._beforeBack = async () => {
this.removeLastPanelRenderer(), this._filterValue = "";
}, this.messages = f(), this._filterValue = "", this._flowItemRenderers = [], this._mode = "profile", this._mutationCounter = 1, this.loading = !1, this.arcgisClose = a({ bubbles: !1 }), this.arcgisItemSelected = a({ bubbles: !1 });
}
static {
this.properties = { _filterValue: 16, _flowItemRenderers: 16, _mode: 16, _mutationCounter: 16, loading: 5, modelId: 1, variable: 0 };
}
static {
this.styles = u;
}
//#endregion
//#region Lifecycle
load() {
this._variableChanged();
}
willUpdate(e) {
e.has("modelId") && (this._flowItemRenderers = []), e.has("variable") && this._variableChanged();
}
disconnectedCallback() {
super.disconnectedCallback(), this._flowObserver?.disconnect();
}
//#endregion
//#region Private Methods
_variableChanged() {
this._mode = this.variable?.type === "featureSet" ? "featureSet" : "profile";
}
addPanelRenderer(e) {
this._flowItemRenderers = [...this._flowItemRenderers, e];
}
removeLastPanelRenderer() {
this._flowItemRenderers = this._flowItemRenderers.slice(0, -1);
}
_isMode(e) {
return this._mode === e;
}
flowFocusHandler(e) {
if (!e) {
this._flowObserver?.disconnect(), this._flowObserver = void 0;
return;
}
this._flowObserver || (this._flowObserver = new MutationObserver(() => {
d(e.querySelector("calcite-flow-item:last-child"), "calcite-input");
}), this._flowObserver.observe(e, { attributes: !0, attributeFilter: ["id"], childList: !0 }));
}
_updateFilterValue(e) {
this._filterValue = e.currentTarget.value;
}
_emitClose() {
this.arcgisClose.emit();
}
_backToTop() {
this._flowItemRenderers = [];
}
_emitItemSelected(e, t) {
if (t.nonInteractive)
return;
const i = e;
(!i.key || i.key === "Enter") && (e.preventDefault(), this.arcgisItemSelected.emit(t.snippet));
}
_showCollectionPanel(e, t) {
e.stopPropagation(), this.addPanelRenderer(
// Add a function to render the variable
(i) => this.renderCollectionBasedVariable(t, !1, i)
);
}
_getHeadingForCollection(e) {
if (!e)
return "";
switch (this._mode) {
case "profile":
return this.messages.profilevariables ?? "";
case "featureSet":
return this.messages.fields ?? "";
}
}
_getDescriptionForCollection(e) {
if (!e)
return "";
switch (this._mode) {
case "profile":
return e.breadcrumb;
case "featureSet":
return e.variables[0]?.getLabel() ?? "";
}
}
//#endregion
//#region Rendering
renderCollectionBasedVariable(e, t = !1, i = !1) {
if (!e)
return null;
let r = this.loading;
return !r && !e.loaded && (e.loadSource().then(() => setTimeout(() => {
this._mutationCounter += 1;
})).catch(() => {
console.error("Error loading collection"), r = !1;
}), r = !0), s`<calcite-flow-item .heading=${this._getHeadingForCollection(e)} .description=${this._getDescriptionForCollection(e)} .beforeBack=${this._beforeBack} closable =${this._emitClose} .selected=${i}><calcite-action slot=header-actions-end .text=${this.messages.backtotop ?? ""} scale=m .hidden=${t || this._isMode("featureSet")} icon=chevrons-left icon-flip-rtl =${this._backToTop}></calcite-action><calcite-input .value=${this._filterValue} icon=magnifying-glass clearable =${this._updateFilterValue} class="sticky" scale=m></calcite-input>${r ? s`<calcite-loader scale=s type=indeterminate .label=${this.messages.loading ?? ""}></calcite-loader>` : s`<calcite-list label=variables>${this.renderEditorVariables(e)}</calcite-list>`}</calcite-flow-item>`;
}
renderEditorVariables(e) {
const t = h(this._filterValue), i = e.variables.filter((r) => r.passFilter(t));
return i.length ? i.map((r) => this.renderEditorVariable(r)) : s`<div class="notice-container">${this.messages.noitems}</div>`;
}
renderEditorVariable(e) {
switch (e.type) {
case "group":
return this._isMode("featureSet") && e.isHeader ? s`<calcite-list-item-group .heading=${e.getLabel()}></calcite-list-item-group>` : this._isMode("featureSet") && e._label?.code === "fields" ? this.renderEditorVariables(e) : s`<calcite-list-item-group .heading=${e.getLabel()}>${this.renderEditorVariables(e)}</calcite-list-item-group>`;
default:
return s`<calcite-list-item .label=${e.getLabel()} .description=${e.getDescription()} =${(t) => this._emitItemSelected(t, e)} =${(t) => this._emitItemSelected(t, e)}>${e.isCollection ? s`<calcite-action slot=actions-end .text=${this.messages.expand ?? ""} scale=s icon=chevron-right icon-flip-rtl =${(t) => this._showCollectionPanel(t, e)} =${g}></calcite-action>` : null}${e.icon ? s`<calcite-icon .icon=${e.icon} scale=s slot=content-start></calcite-icon>` : null}</calcite-list-item>`;
}
}
render() {
return !this.loading && this.variable?.loaded && !this.variable?.variables.length ? s`<calcite-flow><calcite-flow-item .heading=${this.messages.profilevariables} closable =${this._emitClose}><div class="notice-container">${this.messages.noprofilevariablesmessage}</div></calcite-flow-item></calcite-flow>` : s`<calcite-flow ${c(this.flowFocusHandler)}>${this.renderCollectionBasedVariable(this.variable, !0, this._flowItemRenderers.length === 0)}${this._flowItemRenderers.map((e, t, i) => (
// check if the current flow item is the last one, if so, renderer will set selected = true
e(t === i.length - 1)
))}</calcite-flow>`;
}
}
o("arcgis-editor-variables", p);
export {
p as ArcgisEditorVariables
};