@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 3.52 kB
JavaScript
import{_ as e}from"../chunks/tslib.es6.js";import{on as t}from"../core/reactiveUtils.js";import{property as i}from"../core/accessorSupport/decorators/property.js";import"../core/accessorSupport/ensureType.js";import"../core/arrayUtils.js";import{subclass as r}from"../core/accessorSupport/decorators/subclass.js";import s from"./Widget.js";import o from"./Attribution/AttributionViewModel.js";import{accessibleHandler as n}from"./support/decorators/accessibleHandler.js";import{messageBundle as c}from"./support/decorators/messageBundle.js";import{tsx as d}from"./support/jsxFactory.js";import"./support/widgetUtils.js";const l="esri-attribution",p={base:`${l} esri-widget`,poweredBy:`${l}__powered-by`,sources:`${l}__sources`,open:`${l}--open`,sourcesOpen:`${l}__sources--open`,link:`${l}__link`,widgetIcon:"esri-icon-description",interactive:"esri-interactive"};let a=class extends s{constructor(e,t){super(e,t),this._isOpen=!1,this._attributionTextOverflowed=!1,this._prevSourceNodeHeight=0,this._resizeObserver=new ResizeObserver((e=>e.forEach((({target:e})=>this._checkSourceTextOverflow(e))))),this.iconClass=p.widgetIcon,this.itemDelimiter=" | ",this.messages=null,this.viewModel=new o}initialize(){this.addHandles(t((()=>this.viewModel?.items),"change",(()=>this.scheduleRender())))}destroy(){this._resizeObserver?.disconnect()}get _isInteractive(){return this._isOpen||this._attributionTextOverflowed}get attributionText(){return this.viewModel.items.reduce(((e,t)=>(e.includes(t.text)||e.push(t.text),e)),[]).join(this.itemDelimiter)}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}render(){const e={[p.open]:this._isOpen};return d("div",{bind:this,class:this.classes(p.base,e),dir:"ltr",onclick:this._toggleState,onkeydown:this._toggleState},this.renderSourcesNode(),this.renderPoweredBy())}renderPoweredBy(){return d("div",{class:p.poweredBy},"Powered by"," ",d("a",{class:p.link,href:"http://www.esri.com/",target:"_blank",rel:"noreferrer"},"Esri"))}renderSourcesNode(){const e=this._isOpen,t=this._isInteractive,i=t?"0":"",{attributionText:r}=this,s={[p.sourcesOpen]:e,[p.interactive]:t};return d("div",{afterCreate:this._afterSourcesNodeCreate,bind:this,class:this.classes(p.sources,s),innerHTML:r,tabindex:i})}_afterSourcesNodeCreate(e){this._prevSourceNodeHeight=e.clientWidth,this._resizeObserver.observe(e)}_checkSourceTextOverflow(e){let t=!1;const{clientHeight:i,clientWidth:r,scrollWidth:s}=e,o=s>r,n=this._attributionTextOverflowed!==o;if(this._attributionTextOverflowed=o,n&&(t=!0),this._isOpen){const e=i<this._prevSourceNodeHeight;this._prevSourceNodeHeight=i,e&&(this._isOpen=!1,t=!0)}t&&this.scheduleRender()}_toggleState(){this._isInteractive&&(this._isOpen=!this._isOpen)}};e([i()],a.prototype,"_isOpen",void 0),e([i()],a.prototype,"_isInteractive",null),e([i()],a.prototype,"_attributionTextOverflowed",void 0),e([i()],a.prototype,"_prevSourceNodeHeight",void 0),e([i({readOnly:!0,dependsOn:["viewModel.items.length","itemDelimiter"]})],a.prototype,"attributionText",null),e([i()],a.prototype,"iconClass",void 0),e([i()],a.prototype,"itemDelimiter",void 0),e([i()],a.prototype,"label",null),e([i(),c("esri/widgets/Attribution/t9n/Attribution")],a.prototype,"messages",void 0),e([i()],a.prototype,"view",null),e([i({type:o})],a.prototype,"viewModel",void 0),e([n()],a.prototype,"_toggleState",null),a=e([r("esri.widgets.Attribution")],a);const h=a;export{h as default};