UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 3.91 kB
import{_ as e}from"../../../chunks/tslib.es6.js";import{on as t}from"../../../core/events.js";import{isSome as o,removeMaybe as s,destroyMaybe as r,unwrap as i,applySome as n}from"../../../core/maybe.js";import{isMeasurementSystem as l}from"../../../core/unitUtils.js";import{property as a}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import{subclass as c}from"../../../core/accessorSupport/decorators/subclass.js";import p from"../../Widget.js";import{SETTINGS_CSS as h}from"../css.js";import u from"../../support/Popover.js";import{getDir as m}from"../../support/widgetUtils.js";import{messageBundle as _}from"../../support/decorators/messageBundle.js";import{tsx as f}from"../../support/jsxFactory.js";let v=class extends p{constructor(e,t){super(e,t),this._popover=null,this._buttonElement=null,this._focusOutElement=null,this._requestFocusOnCreate=!1}destroy(){this._destroyPopover()}render(){const{unitSelector:e,uniformChartScalingToggle:t}=this.visibleElements;if(!e&&!t)return f("div",{key:`${this.id}-empty`});const s=o(this._popover)&&this._popover.open?this._messages.hideSettings:this._messages.showSettings;return f("button",{class:h.base,title:s,bind:this,afterCreate:this._initializePopover,onclick:this._togglePopover,"aria-label":s,type:"button"})}_initializePopover(e){this._destroyPopover(),this._buttonElement=e,this._popover=new u({owner:this,placement:"bottom-end",offset:[0,0],anchorElement:e,renderContentFunction:()=>this._renderPopoverContent()})}_destroyPopover(){this._focusOutElement=s(this._focusOutElement),this._popover=r(this._popover)}_renderPopoverContent(){const{unitSelector:e,uniformChartScalingToggle:t}=this.visibleElements;return f("div",{class:h.popoverContent,dir:m(i(this._buttonElement)),bind:this,afterCreate:this._onPopoverContentAfterCreate},e&&this._renderUnitSelector(),t&&this._renderUniformChartScalingToggle())}_renderUnitSelector(){const{unit:e,unitOptions:t}=this.viewModel,o=this._messagesUnits;return f("label",{key:"unit-selector-label",class:h.selectLabel},this._messages.unitSelectLabel,f("select",{class:h.select,value:e,bind:this,onchange:this._onUnitChange,afterCreate:this._onUnitSelectAfterCreate},t.map((e=>f("option",{key:e,value:e},l(e)?o.systems[e]:o.units[e].pluralCapitalized)))))}_onUnitChange(e){this.viewModel.unit=e.target.value}_onUnitSelectAfterCreate(e){this._requestFocusOnCreate&&(this._requestFocusOnCreate=!1,e.focus())}_renderUniformChartScalingToggle(){const e=this._messages,t=this.viewModel.uniformChartScaling,o=t?e.uniformChartScalingDisable:e.uniformChartScalingEnable;return f("label",{key:"uniform-chart-scaling-label",class:h.checkboxLabel,onmousedown:g},f("input",{class:this.classes(h.checkbox,h.uniformChartScalingCheckbox),type:"checkbox",checked:t,title:o,"aria-label":o,bind:this,onchange:this._onUniformChartScalingChange}),e.uniformChartScalingLabel)}_onUniformChartScalingChange(e){this.viewModel.uniformChartScaling=e.target.checked}_togglePopover(e){o(this._popover)&&this._popover.open?this._closePopover():this._openPopover()}_openPopover(){n(this._popover,(e=>e.open=!0)),this._requestFocusOnCreate=!0}_closePopover({focusOnButton:e=!0}={}){n(this._popover,(e=>e.open=!1)),e&&n(this._buttonElement,(e=>e.focus()))}_onPopoverContentAfterCreate(e){s(this._focusOutElement),this._focusOutElement=t(e,"focusout",(({relatedTarget:t})=>{const o=e.contains(t),s=t===this._buttonElement;o||s||this._closePopover({focusOnButton:!1})}))}};function g(e){e.preventDefault()}e([a()],v.prototype,"viewModel",void 0),e([a()],v.prototype,"visibleElements",void 0),e([a(),_("esri/widgets/ElevationProfile/t9n/ElevationProfile")],v.prototype,"_messages",void 0),e([a(),_("esri/core/t9n/Units")],v.prototype,"_messagesUnits",void 0),v=e([c("esri.widgets.ElevationProfile.SettingsButton")],v);export{v as SettingsButton};