@arcgis/map-components
Version:
ArcGIS Map Components
232 lines (231 loc) • 13.9 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { c as $ } from "../../chunks/runtime.js";
import { css as w, html as n } from "lit";
import { ref as y } from "lit/directives/ref.js";
import { u as I } from "../../chunks/useT9n.js";
import { classes as M } from "@arcgis/toolkit/dom";
import { usePropertyChange as C } from "@arcgis/lumina/controllers";
import { m as x } from "../../chunks/useViewModel.js";
import { LitElement as F, createEvent as b, nothing as _, safeClassMap as L } from "@arcgis/lumina";
import { substitute as T } from "@arcgis/core/intl.js";
import { renderingSanitizer as A } from "@arcgis/core/applications/Components/sanitizerUtils.js";
import { a as D, g as k, c as R, b as V, s as c, i as B, d as H } from "../../chunks/feature-utils.js";
import N from "@arcgis/core/core/Collection.js";
import { watch as P } from "@arcgis/core/core/reactiveUtils.js";
import { stripHTML as Z } from "@arcgis/core/applications/Components/stringUtils.js";
import E from "@arcgis/core/widgets/Feature/FeatureViewModel.js";
const z = w`:host{display:flex;flex:1 1 auto;background-color:var(--calcite-color-foreground-1);--calcite-color-background: var(--calcite-color-foreground-1)}.root{flex:1 1 auto}.root calcite-icon{box-sizing:content-box}.loading-container{display:flex;justify-content:center;padding:var(--calcite-spacing-md) 0;width:100%}.content-element{margin-bottom:var(--calcite-spacing-lg);padding:0 var(--calcite-spacing-sm);display:flex;flex-direction:column}.content-element:only-child,.content-element:last-child{margin-bottom:var(--calcite-spacing-xxs)}.last-edited-info{padding-top:var(--calcite-spacing-xs);font-size:var(--calcite-font-size-sm)}`, U = x(E);
class S extends F {
constructor() {
super(...arguments), this.messages = I(), this._rootFlowNode = null, this.internalFlowItems = new N(), this.flowType = "feature", this.viewModel = U(this), this.view = this.viewModel.view, this.icon = "icon", this.isFeatureFromTable = this.viewModel.isFeatureFromTable, this.graphic = this.viewModel.graphic, this.defaultPopupTemplateEnabled = this.viewModel.defaultPopupTemplateEnabled, this.headingLevel = 2, this.spatialReference = this.viewModel.spatialReference, this.timeZone = this.viewModel.timeZone, this.heading = this.viewModel.title, this.map = this.viewModel.map, this.chartAnimationDisabled = this.viewModel.abilities.chartAnimation, this.hideHeading = !1, this.hideContent = !1, this.hideAttachmentsContent = !1, this.hideCustomContent = !1, this.hideExpressionContent = !1, this.hideFieldsContent = !1, this.hideMediaContent = !1, this.showRelationshipContent = !1, this.hideTextContent = !1, this.showUtilityNetworkContent = !1, this.hideLastEditedInfo = !1, this.autoDestroyDisabled = !1, this.location = this.viewModel.location, this.state = this.viewModel.state, this.arcgisPropertyChange = C()("flowItems", "state"), this.arcgisReady = b();
}
static {
this.properties = { popupTemplate: 16, sourceLayer: 16, fieldInfoMap: 16, values: 16, globalValues: 16, internalFlowItems: 16, flowType: 1, viewModel: 0, view: 0, flowItems: 0, referenceElement: 1, icon: 1, isFeatureFromTable: 36, graphic: 0, defaultPopupTemplateEnabled: 5, headingLevel: 9, spatialReference: 0, timeZone: 1, heading: 0, map: 0, chartAnimationDisabled: 5, hideHeading: 5, hideContent: 5, hideAttachmentsContent: 5, hideCustomContent: 5, hideExpressionContent: 5, hideFieldsContent: 5, hideMediaContent: 5, showRelationshipContent: 5, hideTextContent: 5, showUtilityNetworkContent: 5, hideLastEditedInfo: 5, autoDestroyDisabled: 5, messageOverrides: 0, label: 1, location: 0, state: 32 };
}
static {
this.styles = z;
}
get popupTemplate() {
return D(this.graphic, this.defaultPopupTemplateEnabled) ?? void 0;
}
get sourceLayer() {
return k(this.graphic);
}
get fieldInfoMap() {
return R(V(this.popupTemplate), this.sourceLayer);
}
get values() {
return this.graphic?.attributes ?? {};
}
get globalValues() {
return this.viewModel.formattedAttributes?.global ?? {};
}
async destroy() {
this._removeFlowItems(), await this.manager.destroy();
}
async nextMedia(e) {
return this.viewModel.nextMedia(e);
}
async previousMedia(e) {
return this.viewModel.previousMedia(e);
}
async setActiveMedia(e, t) {
return this.viewModel.setActiveMedia(e, t);
}
async updateGeometry() {
return await this.viewModel.updateGeometry();
}
loaded() {
this.manager.onLifecycle(() => [
P(() => [this.internalFlowItems?.length], () => this._setFocus())
]);
}
_removeFlowItems() {
this.internalFlowItems?.destroyAll();
}
_storeRootFlowNode(e) {
this._rootFlowNode = e;
}
_setFocus() {
this._rootFlowNode?.setFocus();
}
_handleDrillInBackClick() {
this.internalFlowItems?.pop()?.destroy();
}
render() {
const { state: e } = this.viewModel, t = n`<div class="container">${e === "error" ? this._renderError() : this._renderContentContainer()}</div>`;
return n`<div class="root">${t}</div>`;
}
_renderError() {
const { messages: e, hideHeading: t } = this;
return n`<calcite-notice icon=exclamation-mark-circle kind=danger open scale=s>${t ? null : n`<div slot=title>${e.error}</div>`}<div slot=message>${e.loadingError}</div></calcite-notice>`;
}
_renderAttachments(e) {
const { values: t, fieldInfoMap: i, sourceLayer: o, globalValues: s } = this, a = c({
values: t,
fieldInfoMap: i,
globalValues: s,
layer: o,
text: e.title
}), r = c({
values: t,
fieldInfoMap: i,
globalValues: s,
layer: o,
text: e.description
});
return n`<arcgis-feature-attachments .headingLevel=${this.headingLevel} .heading=${a} class="content-element" .displayType=${e.displayType} .attachmentKeywords=${e.attachmentKeywords ?? void 0} .attachmentTypes=${e.attachmentTypes ?? void 0} .orderByFields=${e.orderByFields ?? void 0} .graphic=${this.graphic ?? void 0} .description=${r} .messages=${this.messages}></arcgis-feature-attachments>`;
}
_renderCustom(e) {
return n`<arcgis-feature-content .creator=${e.creator} .destroyer=${e.destroyer ?? void 0} .graphic=${this.graphic ?? void 0} class="content-element"></arcgis-feature-content>`;
}
_renderFields(e, t) {
const i = this.viewModel.formattedAttributes, { values: o, fieldInfoMap: s, sourceLayer: a, popupTemplate: r, globalValues: l, graphic: d } = this, h = !!e?.fieldInfos, u = (e.fieldInfos ?? r?.fieldInfos ?? [])?.filter(({ fieldName: m }) => !!m && (B(m) || H(m) || m in o)), f = r?.expressionInfos, g = c({
values: o,
fieldInfoMap: s,
globalValues: l,
layer: a,
text: e.title
}), v = c({
values: o,
fieldInfoMap: s,
globalValues: l,
layer: a,
text: e.description
});
return n`<arcgis-feature-fields .headingLevel=${this.headingLevel} .heading=${g} class="content-element" .messages=${this.messages} .graphic=${d ?? void 0} .isContentFieldInfos=${h} .layer=${a} .description=${v} .values=${{
...i?.global,
...i?.content?.[t]
}} .fieldInfos=${u} .expressionInfos=${f ?? void 0}></arcgis-feature-fields>`;
}
_renderMedia(e, t) {
const { values: i, graphic: o, fieldInfoMap: s, sourceLayer: a, popupTemplate: r, globalValues: l } = this, { formattedAttributes: d, relatedInfos: h } = this.viewModel, p = {
...d?.global,
...d?.content?.[t]
}, u = c({
values: i,
fieldInfoMap: s,
globalValues: l,
layer: a,
text: e.title
}), f = c({
values: i,
fieldInfoMap: s,
globalValues: l,
layer: a,
text: e.description
});
return n`<arcgis-feature-media .activeMediaInfoIndex=${e.activeMediaInfoIndex ?? 0} .chartAnimationDisabled=${this.chartAnimationDisabled} .headingLevel=${this.headingLevel} .heading=${u} class="content-element" .description=${f} .values=${i} .layer=${a} .graphic=${o ?? void 0} .messages=${this.messages} .fieldInfoMap=${s} .mediaInfos=${e.mediaInfos ?? []} .popupTemplate=${r ?? void 0} .relatedInfos=${h} .formattedValues=${p}></arcgis-feature-media>`;
}
_renderText(e) {
return n`<arcgis-feature-content .creator=${e.text} .graphic=${this.graphic ?? void 0} class="content-element"></arcgis-feature-content>`;
}
_renderExpression(e, t) {
const i = this.viewModel.formattedAttributes, { fieldInfoMap: o } = this;
return n`<arcgis-feature-expression .expressionInfo=${e.expressionInfo} .map=${this.map ?? void 0} .spatialReference=${this.spatialReference ?? void 0} .view=${this.viewModel.view ?? void 0} .graphic=${this.graphic ?? void 0} .location=${this.location ?? void 0} .headingLevel=${this.headingLevel} class="content-element" .interceptor=${this.viewModel.interceptor} .messages=${this.messages} .fieldInfoMap=${o} .values=${{
...i?.global,
...i?.content?.[t]
}}></arcgis-feature-expression>`;
}
_renderRelationship(e, t) {
const { values: i, graphic: o, fieldInfoMap: s, sourceLayer: a, globalValues: r } = this, { displayCount: l, orderByFields: d, relationshipId: h } = e, { formattedAttributes: p, view: u } = this.viewModel, f = {
...p?.global,
...p?.content?.[t]
}, g = c({
values: i,
fieldInfoMap: s,
globalValues: r,
layer: a,
text: e.title
}), v = c({
values: i,
fieldInfoMap: s,
globalValues: r,
layer: a,
text: e.description
});
return n`<arcgis-feature-relationship .autoDestroyDisabled=${this.autoDestroyDisabled} class="content-element" .flowItems=${this.flowItems ?? this.internalFlowItems} .description=${v} .layer=${a} .map=${this.map ?? void 0} .displayCount=${l} .graphic=${o ?? void 0} .heading=${g} .headingLevel=${this.headingLevel} .messages=${this.messages} .orderByFields=${d ?? void 0} .relationshipId=${h ?? void 0} .spatialReference=${this.spatialReference ?? void 0} .timeZone=${this.timeZone ?? void 0} .values=${f} .view=${u ?? void 0}></arcgis-feature-relationship>`;
}
_renderAssociation(e) {
const { fieldInfoMap: t, globalValues: i, graphic: o, messages: s, sourceLayer: a, values: r } = this, l = c({
values: r,
fieldInfoMap: t,
globalValues: i,
layer: a,
text: e.title
}), d = c({
values: r,
fieldInfoMap: t,
globalValues: i,
layer: a,
text: e.description
});
return n`<arcgis-feature-utility-network-associations .autoDestroyDisabled=${this.autoDestroyDisabled} .associationTypes=${e.associationTypes} class="content-element" .description=${d} .flowItems=${this.flowItems ?? this.internalFlowItems} .graphic=${o ?? void 0} .heading=${l} .headingLevel=${this.headingLevel} .layer=${a} .map=${this.map ?? void 0} .messages=${s} .parentFeatureViewModel=${this.viewModel} .referenceElement=${this.referenceElement} .spatialReference=${this.spatialReference ?? void 0} .timeZone=${this.timeZone ?? void 0} .view=${this.viewModel.view ?? void 0}></arcgis-feature-utility-network-associations>`;
}
_renderContentElement(e, t) {
switch (e.type) {
case "attachments":
return this.hideAttachmentsContent ? null : this._renderAttachments(e);
case "custom":
return this.hideCustomContent ? null : this._renderCustom(e);
case "fields":
return this.hideFieldsContent ? null : this._renderFields(e, t);
case "media":
return this.hideMediaContent ? null : this._renderMedia(e, t);
case "text":
return this.hideTextContent ? null : this._renderText(e);
case "expression":
return this.hideExpressionContent ? null : this._renderExpression(e, t);
case "relationship":
return this.showRelationshipContent ? this._renderRelationship(e, t) : null;
case "utility-network-associations":
return this.showUtilityNetworkContent ? this._renderAssociation(e) : null;
default:
return null;
}
}
_renderContent() {
const { content: e, graphic: t } = this.viewModel;
return e ? Array.isArray(e) && e.length ? e.length ? e.map(this._renderContentElement, this) : null : typeof e == "string" ? n`<arcgis-feature-content .creator=${e} .graphic=${t ?? void 0} class="content-element"></arcgis-feature-content>` : e instanceof HTMLElement ? e : null : null;
}
_renderContentContainer() {
const { flowItems: e, hideContent: t, internalFlowItems: i, headingLevel: o, state: s, messages: a, heading: r, hideHeading: l } = this, d = t ? null : n`<div class="main">${[this._renderContent(), this._renderLastEditInfo()]}</div>`, h = a.returnToInitialFeature ?? "";
return e ? d : n`<calcite-flow ${y(this._storeRootFlowNode)}><calcite-flow-item .loading=${s === "loading"} .headingLevel=${o} .heading=${l ? void 0 : Z(r)} .selected=${!i.length}>${!l && r ? n`<div slot=heading><div .innerHTML=${A.sanitize(r ?? "") ?? ""}></div></div>` : null}${d}</calcite-flow-item>${i.toArray().map((p, u) => n`<calcite-flow-item =${(f) => {
f.preventDefault(), this._handleDrillInBackClick();
}} .loading=${s === "loading"} .headingLevel=${o} .selected=${u === i.length - 1}><calcite-action icon=move-up =${this._removeFlowItems} slot=header-actions-start .text=${h} title=${h ?? _}></calcite-action>${p}</calcite-flow-item>`)}</calcite-flow>`;
}
_renderLastEditInfo() {
const { hideLastEditedInfo: e, messages: t } = this, { lastEditInfo: i } = this.viewModel;
if (!i || e)
return null;
const { date: o, user: s } = i, a = i.type === "edit" ? s ? t.lastEditedByUser : t.lastEdited : s ? t.lastCreatedByUser : t.lastCreated, r = T(a ?? "", {
date: o,
user: s
});
return n`<div class=${L(M("last-edited-info", "content-element"))}>${r}</div>`;
}
}
$("arcgis-feature", S);
export {
S as ArcgisFeature
};