@arcgis/map-components
Version:
ArcGIS Map Components
2 lines • 17.2 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import{a as $}from"./MP6Z45SA.js";import f from"./R3NYK6BO.js";import e from"./KA7BM2DQ.js";import{a as F}from"./HZFVK34O.js";import d from"./LKOVDQTE.js";import c from"./OAWV35F7.js";import{h as w}from"./AKBXFBDL.js";import"./LMBRORN7.js";import a from"./5E6WEUZS.js";import"./PBSJQPB2.js";import{O as g,U as b,a as T,b as r,x as h}from"./WUJCCZQC.js";import"./3TTFCHAA.js";export default $arcgis.t(([{property:l,subclass:x},B,_,{getAllStandardFeatureTemplatesForLayer:D,getTemplatesForLayers:L},{isTable:y,getEffectiveLayerCapabilities:E},{watch:v},,{a:M},,S,{e:m,f:f}])=>{var U=T`:host{display:flex;position:relative;background-color:var(--calcite-color-foreground-1);color:var(--calcite-color-text-2);font-size:var(--calcite-font-size);line-height:var(--calcite-font-line-height-relative-tight)}.filter-no-results{padding:var(--calcite-spacing-md) var(--calcite-spacing-lg)}.root{display:flex;flex:1 1 auto;overflow:hidden auto;transition:max-height .25s ease-in-out}.root>*{width:100%;box-sizing:border-box}.feature-template-tabs{--calcite-tab-background-color: transparent}`,C=Object.defineProperty,R=Object.getOwnPropertyDescriptor,a=(t,e,i,o)=>{for(var n=o>1?void 0:o?R(e,i):e,p=t.length-1,c;p>=0;p--)(c=t[p])&&(n=(o?c(e,i,n):c(n))||n);return o&&n&&C(e,i,n),n};function I(t){switch(t){case"point":case"multipoint":case"polyline":case"polygon":case"extent":case"mesh":return t}return"noneSpecified"}var A=t=>I(t.layer.geometryType??""),s=class extends B{constructor(t){super(t),this._hasRunInitialLoad=!1,this.favoritesEnabled=!1,this.recentlyUsedEnabled=!1,this.hideTemplateDescription=!1,this.filterText="",this.recentFilterText="",this.favoritesFilterText="",this.display="grouped",this.groupBy="layer",this.hideTemplatesMode="never",this.disableTemplatesMode="never",this.sectionSortBy="system",this.templateSortBy="alphabetical",this.sharedTemplatesDisabled=!1,this.excludeTables=!1,this.favorites=new Set,this.fetchingTemplateMetaData=!1,this.recentlyUsed=[]}async handleTemplateSourceDefinitionChanged(){if(this._hasRunInitialLoad=!1,this.applicationTemplates){await this._restore();return}try{this.fetchingTemplateMetaData=!0;let t=this.activeLayers;if(await Promise.allSettled(t.map(e=>e.load())),this.sharedTemplatesDisabled){let e=[];for(let i of t){let o=D(i);o.length>0&&e.push({layer:i,templates:o})}this.mapTemplates=e;return}this.mapTemplates=await L(t,this.view,void 0,{returnVisibleTemplatesOnly:!0}),await this._restore()}catch{this.mapTemplates=[]}finally{this.fetchingTemplateMetaData=!1}}get loading(){return!this._hasRunInitialLoad||this.layers!==void 0||this.applicationTemplates!==void 0||!this.view?.ready}async addFavorite(t){this.favorites.add(t.id),this.favorites=new Set(this.favorites)}async removeFavorite(t){this.favorites.delete(t.id),this.favorites=new Set(this.favorites)}addRecent(t){if(!this.recentlyUsedEnabled)return;let e=this.recentlyUsed.filter(i=>i!==t.id);e.unshift(t.id)>20&&(e.length=20),this.recentlyUsed=e}async removeRecent(t){this.recentlyUsed=this.recentlyUsed.filter(e=>e!==t.id)}async _restore(){try{if(this.favoritesEnabled&&this.restoreFavorites){let t=await this.restoreFavorites();this.favorites=new Set(t??[])}}catch{}try{if(this.recentlyUsedEnabled&&this.restoreRecentlyUsed){let t=await this.restoreRecentlyUsed();this.recentlyUsed=t??[]}}catch{}}_sortTemplates(t){if(this.templateSortByFunction){let e=this.templateSortByFunction(t)??null;return e===null?t:e}return this.templateSortBy==="alphabetical"?t.toSorted((e,i)=>e.label.localeCompare(i.label)):t}_sortSections(t){if(this.sectionSortByFunction){let e=this.sectionSortByFunction(t);e&&(t=e)}else if(this.sectionSortBy==="alphabetical")t=t.toSorted((e,i)=>e.sectionName.localeCompare(i.sectionName));else if(this.groupBy==="geometry"&&!this.groupByFunction){let e={point:1,multipoint:2,polyline:3,polygon:4,extent:5,mesh:6,noneSpecified:7};t=t.toSorted((i,o)=>{let n=e[i.sectionName]??10,p=e[o.sectionName]??10;return n-p})}for(let e of t)e.templates=this._sortTemplates(e.templates);return t}_layerIsVisibleAtCurrentScale(t){if(!this.view)return!0;let e=t;f(t)&&(e=t.parent);let i=this.view.allLayerViews.find(o=>o.layer===e);if(!i)return!0;if(f(t)){let o=this.view.scale;if(i.visibleAtCurrentScale){let n=t.minScale,p=t.maxScale,c=!n,d=!p;return!c&&o<=n&&(c=!0),!d&&o>=p&&(d=!0),c&&d}}return i.visibleAtCurrentScale}get activeLayers(){let t=[];for(let e of this.layers??[])if(m(e))for(let i of e.sublayers)t.push(i);else t.push(e);if(this.layers===void 0||this.layers===null){for(let e of[...this.view?.map?.allLayers?.slice(0).reverse()??[],...this.excludeTables?[]:this.view?.map?.allTables?.slice(0).reverse()??[]])if(e.type==="feature"||e.type==="scene"||e.type==="geojson"||e.type==="oriented-imagery"||e.type==="knowledge-graph")t.push(e);else if(m(e))for(let i of e.sublayers)t.push(i)}return t}get selectedTemplate(){return this.allTemplates.find(t=>t.id===this.selectedTemplateId)}get effectiveTemplates(){return this.templates.map(t=>({...t,templates:t.templates.filter(e=>this.inclusionFilter(e))})).filter(t=>t.templates.length>0)}get templateList(){return this._sortTemplates(this.effectiveTemplates.flatMap(t=>t.templates))}get allTemplates(){return this._sortTemplates(this.templates.flatMap(t=>t.templates))}inclusionFilter(t){if(this.excludeTables&&y(t.layer)||this.applicationFilterFunction?.(t)===!1)return!1;let e=E(t.layer)?.operations;return e?.supportsEditing===!1&&!e?.supportsAdd?!1:y(t.layer)?!0:!(this.hideTemplatesMode==="visible"&&!t.layer.visible||this.hideTemplatesMode==="scale"&&!this._layerIsVisibleAtCurrentScale(t.layer))}get templateSetKey(){return this._sortTemplates(this.allTemplates).map(t=>t.id).join(",")}get disabledTemplates(){let t=new Set;for(let e of this.allTemplates){if(this.applicationDisabledFunction&&this.applicationDisabledFunction(e)){t.add(e);continue}if(!y(e.layer)){if(this.disableTemplatesMode==="visible"&&!e.layer.visible){t.add(e);continue}if(this.disableTemplatesMode==="scale"&&this.view&&!this._layerIsVisibleAtCurrentScale(e.layer)){t.add(e);continue}}}return t}get templates(){return this.applicationTemplates??this.organizedMapTemplates}get organizedMapTemplates(){if(this.groupByFunction||this.groupBy==="geometry"){let t=!this.groupByFunction,e=this.groupByFunction??A,i=new Map;for(let o of this.mapTemplates??[])for(let n of o.templates){let p=new _({template:n,layer:o.layer}),c=e(p);if(c!=null)if(i.has(c))i.get(c)?.templates.push(p);else{let d={sectionName:c,...t?{autoTranslate:!0}:{},templates:[p]};i.set(c,d)}}return this._sortSections(Array.from(i.values()))}return this._sortSections((this.mapTemplates??[]).map(({layer:t,templates:e})=>({sectionName:t.title??"",templates:e.map(i=>new _({layer:t,template:i}))})).filter(t=>t.templates.length>0))}get updating(){return this.fetchingTemplateMetaData}get favoriteTemplates(){let t=[];for(let e of this.effectiveTemplates)for(let i of e.templates)this.favorites.has(i.id)&&t.push(i);return t}get recentTemplates(){let t=new Map;for(let i of this.effectiveTemplates)for(let o of i.templates)t.set(o.id,o);let e=[];for(let i of this.recentlyUsed)t.has(i)&&e.push(t.get(i));return e}};a([l()],s.prototype,"loading",1);a([l()],s.prototype,"_hasRunInitialLoad",2);a([l()],s.prototype,"activeLayers",1);a([l()],s.prototype,"favoritesEnabled",2);a([l()],s.prototype,"recentlyUsedEnabled",2);a([l()],s.prototype,"hideTemplateDescription",2);a([l()],s.prototype,"filterText",2);a([l()],s.prototype,"recentFilterText",2);a([l()],s.prototype,"favoritesFilterText",2);a([l()],s.prototype,"selectedTemplateId",2);a([l()],s.prototype,"selectedTemplate",1);a([l()],s.prototype,"layers",2);a([l()],s.prototype,"restoreFavorites",2);a([l()],s.prototype,"restoreRecentlyUsed",2);a([l()],s.prototype,"applicationDisabledFunction",2);a([l()],s.prototype,"applicationFilterFunction",2);a([l()],s.prototype,"display",2);a([l()],s.prototype,"groupBy",2);a([l()],s.prototype,"hideTemplatesMode",2);a([l()],s.prototype,"disableTemplatesMode",2);a([l()],s.prototype,"groupByFunction",2);a([l()],s.prototype,"sectionSortBy",2);a([l()],s.prototype,"templateSortBy",2);a([l()],s.prototype,"sectionSortByFunction",2);a([l()],s.prototype,"templateSortByFunction",2);a([l()],s.prototype,"sharedTemplatesDisabled",2);a([l()],s.prototype,"excludeTables",2);a([l()],s.prototype,"favorites",2);a([l()],s.prototype,"effectiveTemplates",1);a([l()],s.prototype,"templateList",1);a([l()],s.prototype,"allTemplates",1);a([l()],s.prototype,"templateSetKey",1);a([l()],s.prototype,"disabledTemplates",1);a([l()],s.prototype,"templates",1);a([l()],s.prototype,"mapTemplates",2);a([l()],s.prototype,"organizedMapTemplates",1);a([l()],s.prototype,"fetchingTemplateMetaData",2);a([l()],s.prototype,"updating",1);a([l()],s.prototype,"applicationTemplates",2);a([l()],s.prototype,"favoriteTemplates",1);a([l()],s.prototype,"recentTemplates",1);a([l()],s.prototype,"recentlyUsed",2);a([l()],s.prototype,"view",2);s=a([x("components.feature-templates.FeatureTemplatesViewModel")],s);var N=S(s),u=class extends g{constructor(){super(...arguments),this._messages=F(),this.viewModel=N(this),this.favoritesEnabled=this.viewModel.favoritesEnabled,this.favorites=this.viewModel.favorites,this.restoreFavorites=this.viewModel.restoreFavorites,this.restoreRecentlyUsed=this.viewModel.restoreRecentlyUsed,this.recentlyUsed=this.viewModel.recentlyUsed,this.sharedTemplatesDisabled=this.viewModel.sharedTemplatesDisabled,this.filterText=this.viewModel.filterText,this.recentFilterText=this.viewModel.recentFilterText,this.favoritesFilterText=this.viewModel.favoritesFilterText,this.recentlyUsedEnabled=this.viewModel.recentlyUsedEnabled,this.excludeTables=this.viewModel.excludeTables,this.effectiveTemplates=this.viewModel.effectiveTemplates,this.applicationTemplates=this.viewModel.applicationTemplates,this.selectedTemplateId=this.viewModel.selectedTemplateId,this.selectedTemplate=this.viewModel.selectedTemplate,this.applicationFilterFunction=this.viewModel.applicationFilterFunction,this.applicationDisabledFunction=this.viewModel.applicationDisabledFunction,this.display=this.viewModel.display,this.groupBy=this.viewModel.groupBy,this.sectionSortBy=this.viewModel.sectionSortBy,this.templateSortBy=this.viewModel.templateSortBy,this.templateSortByFunction=this.viewModel.templateSortByFunction,this.sectionSortByFunction=this.viewModel.sectionSortByFunction,this.hideTemplatesMode=this.viewModel.hideTemplatesMode,this.disableTemplatesMode=this.viewModel.disableTemplatesMode,this.groupByFunction=this.viewModel.groupByFunction,this.hideTemplateDescription=this.viewModel.hideTemplateDescription,this.layers=this.viewModel.layers,this.view=M(this),this.autoDestroyDisabled=!1,this.updating=this.viewModel.updating,this.disabled=!1,this.showCollapseButton=!1,this.showFilter=!1,this.minRequiredFilterCount=2,this.arcgisPropertyChange=w()("effectiveTemplates","filterText","recentlyUsed","favorites"),this.arcgisReady=h(),this.arcgisTemplatesChanged=h(),this.arcgisSelectTemplate=h()}static{this.properties={favoritesEnabled:5,favorites:32,restoreFavorites:0,restoreRecentlyUsed:0,recentlyUsed:32,sharedTemplatesDisabled:5,filterText:1,recentFilterText:1,favoritesFilterText:1,recentlyUsedEnabled:5,excludeTables:5,effectiveTemplates:32,applicationTemplates:0,selectedTemplateId:1,selectedTemplate:32,applicationFilterFunction:0,applicationDisabledFunction:0,display:1,groupBy:1,sectionSortBy:1,templateSortBy:1,templateSortByFunction:0,sectionSortByFunction:0,hideTemplatesMode:1,disableTemplatesMode:1,groupByFunction:0,hideTemplateDescription:5,layers:0,view:0,referenceElement:1,autoDestroyDisabled:5,updating:32,disabled:5,showCollapseButton:5,showFilter:5,minRequiredFilterCount:9}}static{this.styles=U}async destroy(){await this.manager.destroy()}loaded(){this.manager.onLifecycle(()=>[v(()=>this.view,()=>{this.viewModel.view=this.view},{initial:!0}),v(()=>this.viewModel.templateSetKey,()=>{this.arcgisTemplatesChanged.emit()}),v(()=>[this.viewModel.activeLayers?.map(e=>e.id).join(","),this.viewModel?.applicationTemplates,this.viewModel?.sharedTemplatesDisabled],$(()=>this.viewModel.handleTemplateSourceDefinitionChanged(),10),{initial:!0})])}_handleSelectTemplate(e){this.selectedTemplateId=e.id,this.arcgisSelectTemplate.emit({template:e}),this.viewModel.addRecent(e)}_removeTemplateFromList(e,i){if(i==="favorites"){this.viewModel.removeFavorite(e);return}this.viewModel.removeRecent(e)}_renderTemplates(){return this.effectiveTemplates.length===0?r`<calcite-notice icon=list open class="filter-no-results"><div slot=message>${this._messages.noTemplates}</div></calcite-notice>`:r`<calcite-list .filterPlaceholder=${this._messages.filterPlaceholder??""} .filterText=${this.filterText} .label=${this._messages?.templates??""} .filterEnabled=${this.showFilter&&this.viewModel.templateList.length>=this.minRequiredFilterCount} selection-appearance=border selection-mode=single =${e=>{this.filterText=e.target.filterText}}>${this.display==="grouped"?this.effectiveTemplates.map(e=>r`<calcite-list-item-group .heading=${e.autoTranslate?this._messages[e.sectionName]??"":e.sectionName}>${e.templates.map(i=>r`<calcite-list-item .disabled=${this.viewModel.disabledTemplates.has(i)} .label=${i.label} .selected=${i.id===this.selectedTemplateId} .description=${this.hideTemplateDescription?void 0:i.description} .value=${i.id} =${()=>{this._handleSelectTemplate(i)}}><arcgis-template-image slot=content-start .template=${i}></arcgis-template-image>${this._renderAddFavorite(i)}</calcite-list-item>`)}</calcite-list-item-group>`):this.viewModel.templateList.map(e=>r`<calcite-list-item .disabled=${this.viewModel.disabledTemplates.has(e)} .label=${e.label} .selected=${e.id===this.selectedTemplateId} .description=${this.hideTemplateDescription?void 0:e.description} .value=${e.id} =${()=>{this._handleSelectTemplate(e)}}><arcgis-template-image slot=content-start .template=${e}></arcgis-template-image>${this._renderAddFavorite(e)}</calcite-list-item>`)}${this._renderFilteredEmpty()}</calcite-list>`}_renderAddFavorite(e){return this.viewModel.favoritesEnabled?r`<calcite-action slot=actions-end .icon=${this.viewModel.favorites.has(e.id)?"heart-f":"heart"} =${()=>{this.viewModel.favorites.has(e.id)?this.viewModel.removeFavorite(e):this.viewModel.addFavorite(e)}} .text=${this._messages.addFavorite??""}></calcite-action>`:""}_renderList(e){let i=e==="favorites"?this.viewModel.favoriteTemplates:this.viewModel.recentTemplates;return i.length===0?r`<calcite-notice icon=list open class="filter-no-results"><div slot=message>${e==="favorites"?this._messages.noFavorites:this._messages.noRecent}</div></calcite-notice>`:r`<calcite-list .filterText=${e==="favorites"?this.favoritesFilterText:this.recentFilterText} .filterPlaceholder=${this._messages.filterPlaceholder??""} .label=${(e==="favorites"?this._messages.favorites:this._messages.recent)??""} .filterEnabled=${this.showFilter} selection-appearance=border selection-mode=single =${o=>{this.filterText=o.target.filterText}}>${i.map(o=>r`<calcite-list-item .disabled=${this.viewModel.disabledTemplates.has(o)} .label=${o.label} .description=${this.hideTemplateDescription?void 0:o.description} .value=${o.id} =${()=>{this._handleSelectTemplate(o)}}><arcgis-template-image slot=content-start .template=${o}></arcgis-template-image><calcite-action slot=actions-end icon=x =${()=>{this._removeTemplateFromList(o,e)}} .text=${(e==="favorites"?this._messages.removeFavorite:this._messages.removeRecent)??""}></calcite-action></calcite-list-item>`)}${this._renderFilteredEmpty()}</calcite-list>`}_renderFilteredEmpty(){return r`<calcite-notice icon=filter slot=filter-no-results open class="filter-no-results"><div slot=message>${this._messages.noMatchingTemplates}</div></calcite-notice>`}_renderContent(){return this.effectiveTemplates.length===0&&this.viewModel.loading?null:this.favoritesEnabled||this.recentlyUsedEnabled?r`<calcite-tabs class="feature-template-tabs"><calcite-tab-nav slot=title-group><calcite-tab-title icon-start=templates selected>${this._messages.templates}</calcite-tab-title>${this.recentlyUsedEnabled?r`<calcite-tab-title icon-start=clock>${this._messages.recent}</calcite-tab-title>`:""}${this.favoritesEnabled?r`<calcite-tab-title icon-start=heart>${this._messages.favorites}</calcite-tab-title>`:""}</calcite-tab-nav><calcite-tab selected>${this._renderTemplates()}</calcite-tab><calcite-tab>${this._renderList("recent")}</calcite-tab><calcite-tab>${this._renderList("favorites")}</calcite-tab></calcite-tabs>`:this._renderTemplates()}render(){return r`<div class="root">${this._renderContent()}${this.viewModel.updating||this.disabled?r`<calcite-scrim><calcite-loader scale=s label .hidden=${!this.viewModel.updating}></calcite-loader></calcite-scrim>`:null}</div>`}};b("arcgis-feature-templates",u);return u},"core/accessorSupport/decorators","core/Accessor","editing/templates/TemplateListItem","applications/Components/templateUtils","applications/Components/layerUtils","core/reactiveUtils",a,c,d,e,f)