UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) • 9.65 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import t from"../Graphic.js";import{substitute as i}from"../intl.js";import{deprecateWidget as s}from"../core/deprecate.js";import n from"../core/Logger.js";import{watch as r,initial as o}from"../core/reactiveUtils.js";import{property as l,cast as d,subclass as a}from"../core/accessorSupport/decorators.js";import c from"../geometry/Point.js";import p from"./Widget.js";import u from"./Feature/FeatureAttachments.js";import m from"./Feature/FeatureContent.js";import h from"./Feature/FeatureExpression.js";import y from"./Feature/FeatureFields.js";import v from"./Feature/FeatureMedia.js";import g from"./Feature/FeatureRelationship.js";import w from"./Feature/FeatureUtilityNetworkAssociations.js";import f from"./Feature/FeatureViewModel.js";import{css as _}from"./Feature/resources.js";import{FeatureContentMixin as M}from"./Feature/support/FeatureContentMixin.js";import{loadCalciteComponents as E}from"./support/componentsUtils.js";import{globalCss as b}from"./support/globalCss.js";import{Heading as F}from"./support/Heading.js";import{tsx as W,messageBundle as C}from"./support/widget.js";const j={title:!0,content:!0,lastEditedInfo:!0};let k=class extends(M(p)){constructor(e,t){super(e,t),this._contentWidgets=[],this.flowType="feature",this.flowItems=null,this.headingLevel=2,this.messages=null,this.messagesCommon=null,this.visibleElements={...j},this.viewModel=new f,!0!==e?.suppressDeprecationWarning&&(this.announceDeprecation=()=>{s(n.getLogger(this),"Feature","arcgis-feature",{version:"4.34"})})}normalizeCtorArgs(e={}){const{suppressDeprecationWarning:t,...i}=e;return i}initialize(){this.addHandles(r(()=>this.viewModel?.contentViewModels,()=>this._setupContentWidgets(),o))}loadDependencies(){return E({notice:()=>import("@esri/calcite-components/dist/components/calcite-notice"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader")})}destroy(){this._destroyContentWidgets()}get graphic(){return this.viewModel.graphic}set graphic(e){this.viewModel.graphic=e}get defaultPopupTemplateEnabled(){return this.viewModel.defaultPopupTemplateEnabled}set defaultPopupTemplateEnabled(e){this.viewModel.defaultPopupTemplateEnabled=e}get isTable(){return this.viewModel.isFeatureFromTable}get icon(){return"polygon"}set icon(e){this._overrideIfSome("icon",e)}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get location(){return this.viewModel.location}set location(e){this.viewModel.location=e}get spatialReference(){return this.viewModel.spatialReference}set spatialReference(e){this.viewModel.spatialReference=e}get timeZone(){return this.viewModel.timeZone}set timeZone(e){this.viewModel.timeZone=e}get title(){return this.viewModel.title}castVisibleElements(e){return{...j,...e}}get map(){return this.viewModel.map}set map(e){this.viewModel.map=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}setActiveMedia(e,t){return this.viewModel.setActiveMedia(e,t)}nextMedia(e){return this.viewModel.nextMedia(e)}previousMedia(e){return this.viewModel.previousMedia(e)}render(){const{state:e}=this.viewModel,t=W("div",{class:_.container,key:"container"},this._renderTitle(),"error"===e?this._renderError():"loading"===e?this._renderLoading():this._renderContentContainer());return W("div",{class:this.classes(_.base,b.widget)},t)}_renderError(){const{messagesCommon:e,messages:t,visibleElements:i}=this;return W("calcite-notice",{icon:"exclamation-mark-circle",kind:"danger",open:!0,scale:"s"},i.title?W("div",{key:"error-title",slot:"title"},e.errorMessage):null,W("div",{key:"error-message",slot:"message"},t.loadingError))}_renderLoading(){return W("div",{class:_.loadingSpinnerContainer,key:"loading-container"},W("calcite-loader",{inline:!0,label:""}))}_renderContentContainer(){const{visibleElements:e}=this;return e.content?W("div",{class:_.main},[this._renderContent(),this._renderLastEditInfo()]):null}_renderTitle(){const{visibleElements:e,title:t}=this;return e.title?W(F,{class:_.title,innerHTML:t,level:this.headingLevel}):null}_renderContent(){const e=this.viewModel.content,t="content";if(!e)return null;if(Array.isArray(e))return e.length?W("div",{class:_.contentNode,key:`${t}-content-elements`},e.map(this._renderContentElement,this)):null;if("string"==typeof e){const e=this._contentWidgets[0];return!e||e.destroyed?null:W("div",{class:this.classes(_.contentNode,_.contentNodeText),key:`${t}-content`},e.render())}return this.renderNodeContent(e)}_renderContentElement(e,t){const{visibleElements:i}=this;if("boolean"!=typeof i.content&&!i.content?.[e.type])return null;switch(e.type){case"attachments":return this._renderAttachments(t);case"custom":return this._renderCustom(e,t);case"fields":return this._renderFields(t);case"media":return this._renderMedia(t);case"text":return this._renderText(e,t);case"expression":return this._renderExpression(t);case"relationship":return this._renderRelationship(t);case"utility-network-associations":return this._renderAssociation(t);default:return null}}_renderAttachments(e){const t=this._contentWidgets[e];if(!t||t.destroyed)return null;const{state:i,attachmentInfos:s}=t.viewModel;return"loading"===i||s.length>0?W("div",{class:this.classes(_.contentElement),key:this._buildKey("attachments-element",e)},t.render()):null}_renderRelationship(e){const t=this._contentWidgets[e];return t&&!t.destroyed&&this.flowItems?W("div",{class:_.contentElement,key:this._buildKey("relationship-element",e)},t.render()):null}_renderAssociation(e){const t=this._contentWidgets[e];return t&&!t.destroyed&&this.flowItems?W("div",{class:_.contentElement,key:this._buildKey("utility-network-association-element",e)},t.render()):null}_renderExpression(e){const t=this._contentWidgets[e];return t&&!t.destroyed&&t.viewModel.contentElement?W("div",{class:_.contentElement,key:this._buildKey("expression-element",e)},t.render()):null}_renderCustom(e,t){const{creator:i}=e,s=this._contentWidgets[t];return!s||s.destroyed?null:i?W("div",{class:_.contentElement,key:this._buildKey("custom-element",t)},s.render()):null}_renderFields(e){const t=this._contentWidgets[e];return!t||t.destroyed?null:W("div",{class:_.contentElement,key:this._buildKey("fields-element",e)},t.render())}_renderMedia(e){const t=this._contentWidgets[e];return!t||t.destroyed?null:W("div",{class:_.contentElement,key:this._buildKey("media-element",e)},t.render())}_renderLastEditInfo(){const{visibleElements:e,messages:t}=this,{lastEditInfo:s}=this.viewModel;if(!s||!e.lastEditedInfo)return null;const{date:n,user:r}=s,o="edit"===s.type?r?t.lastEditedByUser:t.lastEdited:r?t.lastCreatedByUser:t.lastCreated,l=i(o,{date:n,user:r});return W("div",{class:this.classes(_.lastEditedInfo,_.contentElement),key:"edit-info-element"},l)}_renderText(e,t){const i=e.text,s=this._contentWidgets[t];return!s||s.destroyed?null:i?W("div",{class:this.classes(_.contentElement,_.text),key:this._buildKey("text-element",t)},s.render()):null}_buildKey(e,...t){return`${e}__${this.viewModel?.graphic?.uid||"0"}-${t.join("-")}`}_destroyContentWidget(e){e&&(e.viewModel=null,!e.destroyed&&e.destroy())}_destroyContentWidgets(){this._contentWidgets.forEach(e=>this._destroyContentWidget(e)),this._contentWidgets=[]}_setupContentWidgets(){this._destroyContentWidgets();const{headingLevel:e,visibleElements:t,flowItems:i,viewModel:s}=this,n=s?.content,{contentViewModels:r}=s;if(Array.isArray(n))n.forEach((n,o)=>{if("attachments"===n.type&&(this._contentWidgets[o]=new u({displayType:n.displayType,headingLevel:t.title&&e<6?e+1:e,viewModel:r[o]})),"fields"===n.type&&(this._contentWidgets[o]=new y({viewModel:r[o]})),"media"===n.type&&(this._contentWidgets[o]=new v({viewModel:r[o]})),"text"===n.type&&(this._contentWidgets[o]=new m({viewModel:r[o]})),"custom"===n.type&&(this._contentWidgets[o]=new m({viewModel:r[o]})),"expression"===n.type&&(this._contentWidgets[o]=new h({viewModel:r[o]})),"relationship"===n.type){const e=new g({flowItems:i,featureVisibleElements:t,viewModel:r[o]});this._contentWidgets[o]=e}if("utility-network-associations"===n.type){const e=async e=>{const{viewModel:n,listType:r,title:o}=e;if(!i)return;n.activeAssociationType=r;const{default:l}=await import("./Feature/FeatureUtilityNetworkAssociationList.js"),d=new l({viewModel:n,parentFeatureViewModel:s,listType:r,title:o,featureVisibleElements:t,description:s.title,flowItems:i});i.push(d)},n=new w({flowItems:i,onSelectAssociationType:e,parentFeatureViewModel:s,featureVisibleElements:t,viewModel:r[o]});this._contentWidgets[o]=n}},this);else{const e=r[0];e&&!e.destroyed&&(this._contentWidgets[0]=new m({viewModel:e}))}this.scheduleRender()}};e([l()],k.prototype,"flowType",void 0),e([l({type:t})],k.prototype,"graphic",null),e([l()],k.prototype,"defaultPopupTemplateEnabled",null),e([l()],k.prototype,"flowItems",void 0),e([l()],k.prototype,"headingLevel",void 0),e([l({readOnly:!0})],k.prototype,"isTable",null),e([l()],k.prototype,"icon",null),e([l()],k.prototype,"label",null),e([l({type:c})],k.prototype,"location",null),e([l(),C("esri/widgets/Feature/t9n/Feature")],k.prototype,"messages",void 0),e([l(),C("esri/t9n/common")],k.prototype,"messagesCommon",void 0),e([l()],k.prototype,"spatialReference",null),e([l()],k.prototype,"timeZone",null),e([l({readOnly:!0})],k.prototype,"title",null),e([l()],k.prototype,"visibleElements",void 0),e([d("visibleElements")],k.prototype,"castVisibleElements",null),e([l()],k.prototype,"map",null),e([l()],k.prototype,"view",null),e([l({type:f})],k.prototype,"viewModel",void 0),k=e([a("esri.widgets.Feature")],k);export{k as default};