Feature.js 8.5 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{watch as t,on as s,initial as i}from"../core/reactiveUtils.js";import{property as n}from"../core/accessorSupport/decorators/property.js";import"../core/arrayUtils.js";import{cast as r}from"../core/accessorSupport/decorators/cast.js";import{subclass as o}from"../core/accessorSupport/decorators/subclass.js";import l from"./Widget.js";import d from"./Feature/FeatureAttachments.js";import a from"./Feature/FeatureContent.js";import c from"./Feature/FeatureExpression.js";import p from"./Feature/FeatureFields.js";import u from"./Feature/FeatureMedia.js";import h from"./Feature/FeatureRelationship.js";import m from"./Feature/FeatureViewModel.js";import{CSS as v}from"./Feature/resources.js";import{FeatureContentMixin as y}from"./Feature/support/FeatureContentMixin.js";import{Heading as g}from"./support/Heading.js";import"./support/widgetUtils.js";import{messageBundle as w}from"./support/decorators/messageBundle.js";import{tsx as f}from"./support/jsxFactory.js";import{substitute as M}from"../intl/substitute.js";var E;const _={title:!0,content:!0,lastEditedInfo:!0},b="relationship-handles";let W=E=class extends(y(l)){constructor(e,t){super(e,t),this._contentWidgets=[],this.flowItems=null,this.headingLevel=2,this.messages=null,this.messagesCommon=null,this.messagesURIUtils=null,this.visibleElements={..._},this.viewModel=new m}initialize(){this.addHandles(t((()=>this.viewModel?.contentViewModels),(()=>this._setupContentWidgets()),i))}loadDependencies(){return import("@esri/calcite-components/dist/components/calcite-notice.js")}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 label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get spatialReference(){return this.viewModel.spatialReference}set spatialReference(e){this.viewModel.spatialReference=e}get title(){return this.viewModel.title}castVisibleElements(e){return{..._,...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}render(){const{state:e}=this.viewModel,t=f("div",{class:v.container,key:"container"},this.renderTitle(),"error"===e?this.renderError():"loading"===e?this.renderLoading():this.renderContentContainer());return f("div",{class:this.classes(v.base,v.esriWidget)},t)}setActiveMedia(e,t){return this.viewModel.setActiveMedia(e,t)}nextMedia(e){return this.viewModel.nextMedia(e)}previousMedia(e){return this.viewModel.previousMedia(e)}renderError(){const{messagesCommon:e,messages:t,visibleElements:s}=this;return f("calcite-notice",{active:!0,color:"red",icon:"exclamation-mark-circle",scale:"s"},s.title?f("div",{key:"error-title",slot:"title"},e.errorMessage):null,f("div",{key:"error-message",slot:"message"},t.loadingError))}renderLoading(){return f("div",{key:"loading-container",class:v.loadingSpinnerContainer},f("span",{class:this.classes(v.iconLoading,v.spinner)}))}renderContentContainer(){const{visibleElements:e}=this;return e.content?f("div",{class:v.main},[this.renderContent(),this.renderLastEditInfo()]):null}renderTitle(){const{visibleElements:e,title:t}=this;return e.title?f(g,{level:this.headingLevel,class:v.title,innerHTML:t}):null}renderContent(){const e=this.viewModel.content,t="content";if(!e)return null;if(Array.isArray(e))return e.length?f("div",{class:v.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:f("div",{class:v.contentNode,key:`${t}-content`},e.render())}return this.renderNodeContent(e)}renderContentElement(e,t){const{visibleElements:s}=this;if("boolean"!=typeof s.content&&!s.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);default:return null}}renderAttachments(e){const t=this._contentWidgets[e];if(!t||t.destroyed)return null;const{state:s,attachmentInfos:i}=t.viewModel;return"loading"===s||i.length>0?f("div",{key:this._buildKey("attachments-element",e),class:this.classes(v.contentElement)},t.render()):null}renderRelationship(e){const t=this._contentWidgets[e];return t&&!t.destroyed&&this.flowItems?f("div",{key:this._buildKey("relationship-element",e),class:v.contentElement},t.render()):null}renderExpression(e){const t=this._contentWidgets[e];return!t||t.destroyed?null:f("div",{key:this._buildKey("expression-element",e),class:v.contentElement},t.render())}renderCustom(e,t){const{creator:s}=e,i=this._contentWidgets[t];return!i||i.destroyed?null:s?f("div",{key:this._buildKey("custom-element",t),class:v.contentElement},i.render()):null}renderFields(e){const t=this._contentWidgets[e];return!t||t.destroyed?null:f("div",{key:this._buildKey("fields-element",e),class:v.contentElement},t.render())}renderMedia(e){const t=this._contentWidgets[e];return!t||t.destroyed?null:f("div",{key:this._buildKey("media-element",e),class:v.contentElement},t.render())}renderLastEditInfo(){const{visibleElements:e,messages:t}=this,{lastEditInfo:s}=this.viewModel;if(!s||!e.lastEditedInfo)return null;const{date:i,user:n}=s,r="edit"===s.type?n?t.lastEditedByUser:t.lastEdited:n?t.lastCreatedByUser:t.lastCreated,o=M(r,{date:i,user:n});return f("div",{key:"edit-info-element",class:this.classes(v.lastEditedInfo,v.contentElement)},o)}renderText(e,t){const s=e.text,i=this._contentWidgets[t];return!i||i.destroyed?null:s?f("div",{key:this._buildKey("text-element",t),class:this.classes(v.contentElement,v.text)},i.render()):null}_buildKey(e,...t){return`${e}__${this.get("viewModel.graphic.uid")||"0"}-${t.join("-")}`}_destroyContentWidget(e){e&&(e.viewModel=null,!e.destroyed&&e.destroy())}_destroyContentWidgets(){this.removeHandles(b),this._contentWidgets.forEach((e=>this._destroyContentWidget(e))),this._contentWidgets=[]}_addFeatureRelationshipHandles(e){const{flowItems:t,visibleElements:i}=this;this.addHandles([s((()=>e),"select-record",(({featureViewModel:e})=>{t&&(e.abilities={relationshipContent:!0},t.push(new E({flowItems:t,viewModel:e,visibleElements:i})))})),s((()=>e),"show-all-records",(()=>{if(!t)return;const{viewModel:s}=e;s.showAllEnabled=!0;const i=new h({visibleElements:{title:!1,description:!1},viewModel:s});this._addFeatureRelationshipHandles(i),t.push(i)}))],b)}_setupContentWidgets(){this._destroyContentWidgets();const{headingLevel:e,visibleElements:t}=this,s=this.get("viewModel.content"),{contentViewModels:i}=this.viewModel;if(Array.isArray(s))s.forEach(((s,n)=>{if("attachments"===s.type&&(this._contentWidgets[n]=new d({displayType:s.displayType,headingLevel:t.title?e+1:e,viewModel:i[n]})),"fields"===s.type&&(this._contentWidgets[n]=new p({viewModel:i[n]})),"media"===s.type&&(this._contentWidgets[n]=new u({viewModel:i[n]})),"text"===s.type&&(this._contentWidgets[n]=new a({viewModel:i[n]})),"custom"===s.type&&(this._contentWidgets[n]=new a({viewModel:i[n]})),"expression"===s.type&&(this._contentWidgets[n]=new c({viewModel:i[n]})),"relationship"===s.type){const e=new h({viewModel:i[n]});this._addFeatureRelationshipHandles(e),this._contentWidgets[n]=e}}),this);else{const e=i[0];e&&!e.destroyed&&(this._contentWidgets[0]=new a({viewModel:e}))}this.scheduleRender()}};e([n()],W.prototype,"graphic",null),e([n()],W.prototype,"defaultPopupTemplateEnabled",null),e([n()],W.prototype,"flowItems",void 0),e([n()],W.prototype,"headingLevel",void 0),e([n()],W.prototype,"label",null),e([n(),w("esri/widgets/Feature/t9n/Feature")],W.prototype,"messages",void 0),e([n(),w("esri/t9n/common")],W.prototype,"messagesCommon",void 0),e([n(),w("esri/widgets/support/t9n/uriUtils")],W.prototype,"messagesURIUtils",void 0),e([n()],W.prototype,"spatialReference",null),e([n({readOnly:!0})],W.prototype,"title",null),e([n()],W.prototype,"visibleElements",void 0),e([r("visibleElements")],W.prototype,"castVisibleElements",null),e([n()],W.prototype,"map",null),e([n()],W.prototype,"view",null),e([n({type:m})],W.prototype,"viewModel",void 0),W=E=e([o("esri.widgets.Feature")],W);const C=W;export{C as default};