@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 15.1 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{_ as e}from"../../chunks/tslib.es6.js";import"../../intl.js";import t from"../../core/Collection.js";import{watch as i}from"../../core/reactiveUtils.js";import{throttle as o}from"../../core/throttle.js";import{property as s}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as n}from"../../core/accessorSupport/decorators/subclass.js";import{fetchMessageBundle as r}from"../../intl/messages.js";import{isFeatureLayer as l,isSubtypeSublayer as a}from"../../layers/support/layerUtils.js";import"../../popup/content/AttachmentsContent.js";import"../../popup/content/Content.js";import"../../popup/content/CustomContent.js";import"../../popup/content/ExpressionContent.js";import"../../popup/content/FieldsContent.js";import"../../popup/content/MediaContent.js";import"../../popup/content/RelationshipContent.js";import"../../popup/content/TextContent.js";import c from"../../popup/content/UtilityNetworkAssociationsContent.js";import{substituteActionImage as d,getActionStyles as p}from"../../support/actions/actionUtils.js";import u from"../Feature.js";import h from"../Spinner.js";import m from"../Widget.js";import{css as g}from"../Feature/resources.js";import{FeatureContentMixin as w}from"../Feature/support/FeatureContentMixin.js";import{css as v}from"../Features/css.js";import _ from"../Features/FeaturesViewModel.js";import{ActionsCollection as f}from"../Popup/actions.js";import{zoomToLocation as y}from"../Popup/actionUtils.js";import{loadCalciteComponents as M}from"../support/componentsUtils.js";import{globalCss as F}from"../support/globalCss.js";import{Heading as A}from"../support/Heading.js";import"../support/widgetUtils.js";import{messageBundle as b}from"../support/decorators/messageBundle.js";import{vmEvent as I}from"../support/decorators/vmEvent.js";import{tsx as k}from"../support/jsxFactory.js";import C from"./UtilityNetworkTraceFeaturesDrillIn.js";import{substitute as T}from"../../intl/substitute.js";const j="selected-index",W=0,N="features-spinner",x="esri-utility-network-trace",S={blockContainer:`${x}__block-container`,blockContent:`${x}__block-content`,featureContent:`${x}__feature-content`,paddingBottom:`${x}__pad-bottom`,paddingTop:`${x}__pad-top`};let L=class extends(w(m)){constructor(e,s){super(e,s),this._actionBarMenuNode=null,this._drillInFlowItems=new t,this._drillInWidget=new C({flowItems:this._drillInFlowItems}),this._feature=null,this._featureMenuViewportNode=null,this._spinner=null,this._utilityNetworkTraceMessages=null,this.featureNavigationTop=!1,this.headerActions=new f,this.headingLevel=2,this.messages=null,this.messagesCommon=null,this.responsiveActionsEnabled=!1,this.viewModel=new _,this._renderAction=(e,t)=>{const i=this._getActionTitle(e),{type:o,active:s,uid:n,disabled:r,indicator:l}=e;return e.visible?k("calcite-action",{active:"toggle"===o&&e.value,appearance:"solid",bind:this,"data-action-uid":n,disabled:"zoom-to-feature"===e.id?!this.feature.geometry:r,icon:this._getActionIcon(e),indicator:l,key:`action-${t}`,loading:s,onclick:this._triggerAction,scale:"s",text:i,title:this._hideActionText?i:void 0},this._renderFallbackIcon(e)):null},this._renderAddNsoBlock=()=>{const{_utilityNetworkTraceMessages:e,messagesCommon:t}=this;return k("calcite-block",{class:S.blockContent,expanded:!this.feature,heading:e?.inputsStrings.addNonspatialOption},k("calcite-action",{icon:"x",onclick:()=>this.emit("close-un-trace-feature-block"),slot:"control",text:t.close}),k("calcite-notice",{icon:"information",kind:"info",open:!this.feature},k("div",{slot:"message"},e?.inputsStrings.addNonspatialHint)))},this._renderNoPopupErrorBlock=()=>{const{_utilityNetworkTraceMessages:e,messagesCommon:t}=this;return k("calcite-block",{description:void 0,expanded:!0,heading:"show-feature-info"===this.mode?t.warning:void 0},k("calcite-notice",{class:this.classes(S.paddingBottom,S.paddingTop),icon:"exclamation-mark-triangle",kind:"danger",open:!0},k("div",{slot:"message"},e.alertsStrings.noPopupConfigured)),"show-feature-info"===this.mode?k("calcite-action",{icon:"x",onclick:()=>this.emit("close-un-trace-feature-block"),slot:"control",text:t.close}):void 0)},this._displaySpinnerThrottled=o((()=>this._displaySpinner()),W),this.addHandles([this._displaySpinnerThrottled,i((()=>this.viewModel?.active),(e=>this._drillInWidget.closed=!e)),i((()=>this.viewModel?.view),((e,t)=>this._viewChange(e,t))),i((()=>this.viewModel?.view?.ready),((e,t)=>this._viewReadyChange(e??!1,t??!1))),i((()=>[this.viewModel?.waitingForResult,this.viewModel?.location]),(()=>{this._hideSpinner(),this._displaySpinnerThrottled()})),i((()=>this.viewModel?.screenLocation),(()=>this._closeOpenActionMenu())),i((()=>this.selectedFeatureWidget),(()=>this._destroyDrillInFlowItemWidgets())),i((()=>{const e=this.selectedFeatureWidget?.viewModel;return[e?.title,e?.state]}),(()=>this._setTitleFromFeatureWidget())),i((()=>{const e=this.selectedFeatureWidget?.viewModel;return[e?.content,e?.state]}),(()=>this._setContentFromFeatureWidget())),i((()=>this.viewModel?.featureViewModels),(()=>this._featureMenuViewportScrollTop())),this._drillInWidget.on("close",(()=>{this.emit("close")})),this._drillInWidget.on("exit",(()=>this._destroyDrillInFlowItemWidgets())),this._drillInWidget.on("open-feature",(({feature:e})=>this._openRelatedFeature(e))),this._drillInWidget.on("zoom-to-feature",(({featureWidget:e})=>y(this.viewModel,e))),this._drillInWidget.on("add-nso-trace-location",(({featureWidget:e})=>this.emit("add-nso-trace-location",{featureWidget:e})))])}initialize(){(async()=>{this._utilityNetworkTraceMessages=await r("esri/widgets/UtilityNetworkTrace/t9n/UtilityNetworkTrace")})(),this._drillInWidget.mode=this.mode,this._drillInWidget.closable=!1}loadDependencies(){return M({action:()=>import("@esri/calcite-components/dist/components/calcite-action"),"action-bar":()=>import("@esri/calcite-components/dist/components/calcite-action-bar"),"action-group":()=>import("@esri/calcite-components/dist/components/calcite-action-group"),block:()=>import("@esri/calcite-components/dist/components/calcite-block"),flow:()=>import("@esri/calcite-components/dist/components/calcite-flow"),"flow-item":()=>import("@esri/calcite-components/dist/components/calcite-flow-item"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice")})}destroy(){this._destroyDrillInFlowItemWidgets(),this._destroySelectedFeatureWidget(),this._destroySpinner(),this._drillInWidget?.destroy()}get _hideActionText(){if(!this.responsiveActionsEnabled)return!1;const e=this.view?.widthBreakpoint;return"xsmall"===e||"small"===e||"medium"===e}get active(){return this.viewModel.active}get content(){return this.viewModel.content}set content(e){this.viewModel.content=e}get feature(){return this.viewModel.features.length?this.viewModel.features[0]:null}set feature(e){this.viewModel.features=e?[e]:[]}get goToOverride(){return this.viewModel.goToOverride}set goToOverride(e){this.viewModel.goToOverride=e}get hasAssociationsPopupElement(){const e=l(this.feature?.sourceLayer)?this.feature?.sourceLayer:void 0,t=a(this.feature?.sourceLayer)?this.feature?.sourceLayer:void 0,i=e?.popupTemplate||t?.popupTemplate||null,o=i?.content;return!(Array.isArray(o)&&!o.some((e=>e instanceof c)))}get hasPopupInfo(){const e=l(this.feature?.sourceLayer)?this.feature?.sourceLayer:void 0,t=a(this.feature?.sourceLayer)?this.feature?.sourceLayer:void 0;return!(!e?.popupTemplate&&!t?.popupTemplate)}get location(){return this.viewModel.location}set location(e){this.viewModel.location=e}get mode(){return this._get("mode")||"add-nso"}set mode(e){this._set("mode",e)}get promises(){return this.viewModel.promises}set promises(e){this.viewModel.promises=e}get selectedFeature(){return this.viewModel.selectedFeature}get selectedDrillInFeature(){const e=Array.from(this._drillInFlowItems).at(-1);if(!e)return null;const{flowType:t}=e;return"feature-association"===t||"feature-relationship"===t?e.graphic??null:null}get selectedFeatureWidget(){const{_feature:e,headingLevel:t,_drillInFlowItems:i,timeZone:o}=this,{selectedFeatureViewModel:s}=this.viewModel,n={title:!1};return s?(e?(e.viewModel=s,e.visibleElements=n):this._feature=new u({flowItems:i,headingLevel:t+1,timeZone:o,viewModel:s,visibleElements:n}),this._feature):null}get timeZone(){return this.viewModel.timeZone}set timeZone(e){this.viewModel.timeZone=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}open(e){this.removeHandles(j),this.viewModel.open({features:[e]})}triggerAction(e){return this.viewModel.triggerAction(e)}render(){return k("div",{bind:this,class:this.classes(v.base,F.widget,F.panel,S.blockContainer)},"add-nso"===this.mode?this._renderAddNsoBlock():void 0,this.feature?this.hasPopupInfo?this._renderContentContainer():this._renderNoPopupErrorBlock():void 0)}_renderActionBar(){return this.viewModel.allActions?.length?k("calcite-action-bar",{expandDisabled:!0,expanded:!this._hideActionText,key:"header-action-bar",scale:"s",slot:"action-bar"},k("calcite-action-group",{afterCreate:e=>this._actionBarMenuNode=e,overlayPositioning:"fixed",scale:"s"},this._renderActions())):null}_renderActions(){return this.viewModel.allActions.toArray().map(this._renderAction)}_renderContent(){const e=this.viewModel?.content;return e?"string"==typeof e?k("div",{class:g.contentNode,innerHTML:e,key:e}):this.renderNodeContent(e):null}_renderContentContainer(){const e=[this._renderContentFeature(),this._drillInWidget.render()];return k("calcite-flow",{key:"content-container"},e)}_renderContentFeature(){const{_drillInFlowItems:e,headingLevel:t,featureNavigationTop:i}=this,{title:o,active:s}=this.viewModel,n=o||"";return k("calcite-flow-item",{bind:this,class:this.classes({[v.contentFeature]:!0}),closed:!s,collapseDirection:i?"down":"up",headingLevel:t,key:"root-flow-item",loading:this.viewModel.waitingForContents,selected:0===e.length},"show-feature-info"===this.mode?k("calcite-action",{icon:"x",onclick:()=>{this.emit("close")},slot:"header-actions-end",text:this.messagesCommon.close}):void 0,n?k(A,{class:this.classes(v.featuresHeading,F.heading),innerHTML:n,key:"header-content",level:this.headingLevel,slot:"header-content"}):null,this._renderHeaderActions(),this._renderActionBar(),k("div",{class:"add-nso"===this.mode?this.classes(v.container,v.contentContainer):this.classes(v.container,v.contentContainer,S.featureContent)},this._renderContent()))}_renderFallbackIcon(e){const{className:t,icon:i}=e;if(i)return null;const o=d({action:e,feature:this.selectedFeature}),s={[v.icon]:!!t,[v.actionImage]:!!o};return t&&(s[t]=!0),o||t?k("span",{"aria-hidden":"true",class:this.classes(v.icon,s),key:"icon",styles:p(o)}):null}_renderHeaderAction(e,t){const i=e.title||"";return e.visible?k("calcite-action",{active:"toggle"===e.type&&e.value,appearance:"solid",bind:this,"data-action-uid":e.uid,disabled:e.disabled||!this.feature.geometry,icon:e.icon??void 0,indicator:e.indicator,key:`header-action-${t}`,loading:e.active,onclick:this._triggerHeaderAction,slot:"header-actions-end",text:i,title:i}):null}_renderHeaderActions(){return this.headerActions.map(((e,t)=>this._renderHeaderAction(e,t))).toArray()}_closeOpenActionMenu(){const{_actionBarMenuNode:e}=this;e&&(e.menuOpen=!1)}_createSpinner(e){e&&(this._spinner=new h({view:e}),e.ui.add(this._spinner,{key:N,position:"manual",internal:!0}))}_destroyDrillInFlowItemWidgets(){this._drillInFlowItems.drain((e=>{"showAllEnabled"in e.viewModel&&(e.viewModel.showAllEnabled=!1),e.viewModel=null,e.destroy()}))}_destroySelectedFeatureWidget(){const{_feature:e}=this;e&&(e.viewModel=null,!e.destroyed&&e.destroy()),this._feature=null}_destroySpinner(){const{_spinner:e,view:t}=this;e&&(t?.ui?.remove(e,N),e.destroy(),this._spinner=null)}_displaySpinner(){const{_spinner:e}=this;if(!e)return;const{location:t,waitingForResult:i}=this.viewModel;i&&t?e.show({location:t}):e.hide()}_featureMenuViewportScrollTop(){this._featureMenuViewportNode&&this._featureMenuViewportNode.scrollContentTo({top:0})}_getActionIcon(e){return e.icon?e.icon:e.image||e.className?void 0:"question"}_getActionTitle(e){const{messages:t,selectedFeature:i,messagesCommon:o}=this,{id:s}=e,n=i?.attributes,r=e.title??"",l="zoom-to-feature"===s?T(r,{messages:t}):"remove-selected-feature"===s?T(r,{messages:o}):"zoom-to-clustered-features"===s||"browse-clustered-features"===s?T(r,{messages:t}):e.title;return l&&n?T(l,n):l??""}_hideSpinner(){const{_spinner:e}=this;e&&(e.location=null,e.hide())}async _openRelatedFeature(e){await e.viewModel.updateGeometry();const t=e.graphic,i=t?.geometry;null!=i&&null!=t&&(this._destroyDrillInFlowItemWidgets(),await this.viewModel.zoomTo({target:i}),this.open(t))}_setContentFromFeatureWidget(){const{selectedFeatureWidget:e}=this;e&&(this.viewModel.content=e)}_setTitleFromFeatureWidget(){const{selectedFeatureWidget:e,messagesCommon:t}=this,i=e?.viewModel;e&&(this.viewModel.title="error"===i?.state?t?.errorMessage:i?.title||"")}_triggerAction(e){const t=e.currentTarget;if(t.disabled)return;const i=t.dataset.actionUid,{allActions:o}=this.viewModel,s=o.findIndex((e=>e.uid===i)),n=o.at(s);n&&"toggle"===n.type&&(n.value=!n.value),this.viewModel.triggerAction(s)}_triggerHeaderAction(e){const t=e.currentTarget;if(t.disabled)return;const i=t.dataset.actionUid,o=this.headerActions.find((({uid:e})=>e===i));o&&!o.disabled&&("toggle"===o?.type&&(o.value=!o.value),this.emit("trigger-header-action",{action:o}))}_viewReadyChange(e,t){e?this._wireUpView(this.viewModel?.view):t&&this.viewModel.clear()}_viewChange(e,t){e&&t&&this.viewModel.clear()}_wireUpView(e){this._destroySpinner(),e&&this._createSpinner(e)}};e([s()],L.prototype,"_drillInFlowItems",void 0),e([s()],L.prototype,"_hideActionText",null),e([s({readOnly:!0})],L.prototype,"active",null),e([s()],L.prototype,"content",null),e([s()],L.prototype,"feature",null),e([s()],L.prototype,"featureNavigationTop",void 0),e([s()],L.prototype,"goToOverride",null),e([s()],L.prototype,"hasAssociationsPopupElement",null),e([s()],L.prototype,"hasPopupInfo",null),e([s({type:f})],L.prototype,"headerActions",void 0),e([s()],L.prototype,"headingLevel",void 0),e([s()],L.prototype,"location",null),e([s(),b("esri/widgets/Features/t9n/Features")],L.prototype,"messages",void 0),e([s(),b("esri/t9n/common")],L.prototype,"messagesCommon",void 0),e([s()],L.prototype,"mode",null),e([s()],L.prototype,"promises",null),e([s()],L.prototype,"responsiveActionsEnabled",void 0),e([s({readOnly:!0})],L.prototype,"selectedFeature",null),e([s({readOnly:!0})],L.prototype,"selectedDrillInFeature",null),e([s({readOnly:!0})],L.prototype,"selectedFeatureWidget",null),e([s()],L.prototype,"timeZone",null),e([s()],L.prototype,"view",null),e([s({type:_}),I(["triggerAction","trigger-action"])],L.prototype,"viewModel",void 0),L=e([n("esri.widgets.UtilityNetworkTrace.UtilityNetworkTraceFeature")],L);const U=L;export{U as default};