UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 4.53 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import{deprecated as t}from"../core/deprecate.js";import has from"../core/has.js";import i from"../core/Logger.js";import{on as r}from"../core/reactiveUtils.js";import{property as s,subclass as o}from"../core/accessorSupport/decorators.js";import n from"./Widget.js";import a from"./Attribution/AttributionViewModel.js";import{globalCss as l}from"./support/globalCss.js";import{messageBundle as c,accessibleHandler as h,tsx as d}from"./support/widget.js";const u="esri-attribution",p={base:u,poweredBy:`${u}__powered-by`,sources:`${u}__sources`,open:`${u}--open`,sourcesOpen:`${u}__sources--open`,link:`${u}__link`};let _=class extends n{constructor(e,r){super(e,r),this._isOpen=!1,this._attributionTextOverflowed=!1,this._prevSourceNodeHeight=0,this._sourcesNode=null,this._overflowRequestAnimationFrame=null,this._resizeObserver=new ResizeObserver(e=>{e.forEach(({target:e})=>{this._scheduleOverflowCheck(e)})}),this._mutationObserver=new MutationObserver(e=>{let t=!1;for(const i of e)if("childList"===i.type||"characterData"===i.type||"attributes"===i.type){t=!0;break}t&&this._sourcesNode&&this._scheduleOverflowCheck(this._sourcesNode)}),this.itemDelimiter=" | ",this.messages=null,this.viewModel=new a,has("esri-deprecation-warnings")&&t(i.getLogger("esri.widgets.Attribution"),"This widget is deprecated. Use attributionVisible and attributionItems on arcgis-map, arcgis-scene, arcgis-link-chart, and View instead.",{replacement:"attributionVisible and attributionItems on arcgis-map, arcgis-scene, arcgis-link-chart, and View",warnOnce:!0})}initialize(){this.addHandles(r(()=>this.viewModel?.items,"change",()=>this.scheduleRender()))}destroy(){this._resizeObserver?.disconnect(),this._mutationObserver?.disconnect(),null!=this._overflowRequestAnimationFrame&&(cancelAnimationFrame(this._overflowRequestAnimationFrame),this._overflowRequestAnimationFrame=null)}get _isInteractive(){return this._isOpen||this._attributionTextOverflowed}_scheduleOverflowCheck(e){null==this._overflowRequestAnimationFrame&&(this._overflowRequestAnimationFrame=requestAnimationFrame(()=>{this._overflowRequestAnimationFrame=null,this._checkSourceTextOverflow(e)}))}get attributionText(){return this.viewModel.items.reduce((e,t)=>(e.includes(t.text)||e.push(t.text),e),[]).join(this.itemDelimiter)}get icon(){return"description"}set icon(e){this._overrideIfSome("icon",e)}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,l.widget,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:"https://www.esri.com/",rel:"noreferrer",target:"_blank"},"Esri"))}_renderSourcesNode(){const e=this._isOpen,t=this._isInteractive,i=t?0:void 0,{attributionText:r}=this,s={[p.sourcesOpen]:e,[l.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._sourcesNode=e,this._resizeObserver.observe(e),this._mutationObserver.observe(e,{subtree:!0,childList:!0,characterData:!0,attributes:!0}),this._scheduleOverflowCheck(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([s()],_.prototype,"_isOpen",void 0),e([s()],_.prototype,"_isInteractive",null),e([s()],_.prototype,"_attributionTextOverflowed",void 0),e([s()],_.prototype,"_prevSourceNodeHeight",void 0),e([s({readOnly:!0})],_.prototype,"attributionText",null),e([s()],_.prototype,"icon",null),e([s()],_.prototype,"itemDelimiter",void 0),e([s()],_.prototype,"label",null),e([s(),c("esri/widgets/Attribution/t9n/Attribution")],_.prototype,"messages",void 0),e([s()],_.prototype,"view",null),e([s({type:a})],_.prototype,"viewModel",void 0),e([h()],_.prototype,"_toggleState",null),_=e([o("esri.widgets.Attribution")],_);const v=_;export{v as default};