Popup.js 37 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.24/esri/copyright.txt for details.
  4. */
  5. import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import t from"../core/Collection.js";import{eventKey as i}from"../core/events.js";import o from"../core/Handles.js";import n from"../core/Logger.js";import{isNone as s}from"../core/maybe.js";import{watch as r,when as a,on as l,whenOnce as u,initial as c}from"../core/reactiveUtils.js";import{throttle as d}from"../core/throttle.js";import{aliasOf as p}from"../core/accessorSupport/decorators/aliasOf.js";import"../core/arrayUtils.js";import"../core/has.js";import{cast as h}from"../core/accessorSupport/decorators/cast.js";import{property as g}from"../core/accessorSupport/decorators/property.js";import{subclass as _}from"../core/accessorSupport/decorators/subclass.js";import f from"./Feature.js";import v from"./Spinner.js";import m from"./Widget.js";import{FeatureContentMixin as b}from"./Feature/support/FeatureContentMixin.js";import M from"./Popup/PopupViewModel.js";import{Heading as w}from"./support/Heading.js";import{accessibleHandler as y}from"./support/decorators/accessibleHandler.js";import{messageBundle as k}from"./support/decorators/messageBundle.js";import{vmEvent as A}from"./support/decorators/vmEvent.js";import{tsx as C}from"./support/jsxFactory.js";import{isRTL as F,storeNode as I,cssTransition as O}from"./support/widgetUtils.js";import{substitute as x}from"../intl/substitute.js";const N="selected-index",T=0,B="popup-spinner",D={iconLeftTriangleArrow:"esri-icon-left-triangle-arrow",iconRightTriangleArrow:"esri-icon-right-triangle-arrow",iconDockToTop:"esri-icon-maximize",iconDockToBottom:"esri-icon-dock-bottom",iconDockToLeft:"esri-icon-dock-left",iconDockToRight:"esri-icon-dock-right",iconClose:"esri-icon-close",iconUndock:"esri-icon-minimize",iconCheckMark:"esri-icon-check-mark",iconLoading:"esri-icon-loading-indicator",iconDefaultAction:"esri-icon-default-action",iconActionsMenu:"esri-icon-handle-horizontal",rotating:"esri-rotating",base:"esri-popup",widget:"esri-widget",main:"esri-popup__main-container",loadingContainer:"esri-popup__loading-container",isCollapsible:"esri-popup--is-collapsible",isCollapsed:"esri-popup--is-collapsed",shadow:"esri-popup--shadow",isDocked:"esri-popup--is-docked",isDockedTopLeft:"esri-popup--is-docked-top-left",isDockedTopCenter:"esri-popup--is-docked-top-center",isDockedTopRight:"esri-popup--is-docked-top-right",isDockedBottomLeft:"esri-popup--is-docked-bottom-left",isDockedBottomCenter:"esri-popup--is-docked-bottom-center",isDockedBottomRight:"esri-popup--is-docked-bottom-right",alignTopCenter:"esri-popup--aligned-top-center",alignBottomCenter:"esri-popup--aligned-bottom-center",alignTopLeft:"esri-popup--aligned-top-left",alignBottomLeft:"esri-popup--aligned-bottom-left",alignTopRight:"esri-popup--aligned-top-right",alignBottomRight:"esri-popup--aligned-bottom-right",isFeatureMenuOpen:"esri-popup--feature-menu-open",isActionsMenuOpen:"esri-popup--actions-menu-open",hasFeatureUpdated:"esri-popup--feature-updated",header:"esri-popup__header",headerButtons:"esri-popup__header-buttons",headerContainer:"esri-popup__header-container",headerContainerButton:"esri-popup__header-container--button",headerTitle:"esri-popup__header-title",content:"esri-popup__content",footer:"esri-popup__footer",footerHasPagination:"esri-popup__footer--has-pagination",footerHasActions:"esri-popup__footer--has-actions",footerHasActionsMenu:"esri-popup__footer--has-actions-menu",button:"esri-popup__button",buttonDisabled:"esri-popup__button--disabled",buttonDock:"esri-popup__button--dock",icon:"esri-popup__icon",iconDock:"esri-popup__icon--dock-icon",inlineActionsContainer:"esri-popup__inline-actions-container",actionsMenuButton:"esri-popup__actions-menu-button",actions:"esri-popup__actions",action:"esri-popup__action",actionImage:"esri-popup__action-image",actionText:"esri-popup__action-text",actionToggle:"esri-popup__action-toggle",actionToggleOn:"esri-popup__action-toggle--on",pointer:"esri-popup__pointer",pointerDirection:"esri-popup__pointer-direction",navigation:"esri-popup__navigation",paginationPrevious:"esri-popup__pagination-previous",paginationNext:"esri-popup__pagination-next",paginationPreviousIconLTR:"esri-popup__pagination-previous-icon",paginationPreviousIconRTL:"esri-popup__pagination-previous-icon--rtl",paginationNextIconLTR:"esri-popup__pagination-next-icon",paginationNextIconRTL:"esri-popup__pagination-next-icon--rtl",featureMenu:"esri-popup__feature-menu",featureMenuList:"esri-popup__feature-menu-list",featureMenuItem:"esri-popup__feature-menu-item",featureMenuViewport:"esri-popup__feature-menu-viewport",featureMenuHeader:"esri-popup__feature-menu-header",featureMenuNote:"esri-popup__feature-menu-note",featureMenuSelected:"esri-popup__feature-menu-item--selected",featureMenuButton:"esri-popup__feature-menu-button",featureMenuTitle:"esri-popup__feature-menu-title",featureMenuObserver:"esri-popup__feature-menu-observer",featureMenuLoader:"esri-popup__feature-menu-loader",collapseButton:"esri-popup__collapse-button"},E={buttonEnabled:!0,position:"auto",breakpoint:{width:544}},P="esri-popup";function L(e,t){return void 0===t?`${P}__${e}`:`${P}__${e}-${t}`}const S="esri.widgets.Popup",V=n.getLogger(S),U={closeButton:!0,featureNavigation:!0};let R=class extends(b(m)){constructor(e,t){super(e,t),this._blurClose=!1,this._blurContainer=!1,this._containerNode=null,this._mainContainerNode=null,this._featureMenuNode=null,this._actionsMenuNode=null,this._focusClose=!1,this._focusContainer=!1,this._focusDockButton=!1,this._focusFeatureMenuButton=!1,this._focusActionsMenuButton=!1,this._focusFirstFeature=!1,this._focusFirstAction=!1,this._handles=new o,this._pointerOffsetInPx=16,this._spinner=null,this._feature=null,this._featureMenuIntersectionObserverCallback=([e])=>{e?.isIntersecting&&this.viewModel.featurePage++},this._featureMenuIntersectionObserver=new IntersectionObserver(this._featureMenuIntersectionObserverCallback,{root:window.document}),this._displaySpinnerThrottled=d((()=>this._displaySpinner()),T),this.actions=null,this.alignment="auto",this.autoCloseEnabled=null,this.autoOpenEnabled=null,this.defaultPopupTemplateEnabled=null,this.content=null,this.collapsed=!1,this.collapseEnabled=!0,this.dockEnabled=!1,this.featureCount=null,this.featureMenuOpen=!1,this.features=null,this.goToOverride=null,this.headingLevel=2,this.highlightEnabled=null,this.location=null,this.label=void 0,this.maxInlineActions=3,this.messages=null,this.messagesCommon=null,this.promises=null,this.selectedFeature=null,this.selectedFeatureIndex=null,this.spinnerEnabled=!0,this.title=null,this.updateLocationEnabled=null,this.view=null,this.viewModel=new M,this.visible=null,this.visibleElements={...U},this._addSelectedFeatureIndexHandle(),this.own([r((()=>this.viewModel?.screenLocation),(()=>this._positionContainer())),r((()=>[this.viewModel?.active,this.dockEnabled]),(()=>this._toggleScreenLocationEnabled())),r((()=>this.viewModel?.screenLocation),((e,t)=>{!!e!=!!t&&this.reposition()})),r((()=>[this.viewModel?.view?.padding,this.viewModel?.view?.size,this.viewModel?.active,this.viewModel?.location,this.alignment]),(()=>this.reposition())),r((()=>this.spinnerEnabled),(e=>this._spinnerEnabledChange(e))),r((()=>this.viewModel?.view?.size),((e,t)=>this._updateDockEnabledForViewSize(e,t))),r((()=>this.viewModel?.view),((e,t)=>this._viewChange(e,t))),r((()=>this.viewModel?.view?.ready),((e,t)=>this._viewReadyChange(e,t))),r((()=>[this.viewModel?.waitingForResult,this.viewModel?.location]),(()=>{this._hideSpinner(),this._displaySpinnerThrottled()})),r((()=>[this.selectedFeatureWidget?.viewModel?.title,this.selectedFeatureWidget?.viewModel?.state]),(()=>this._setTitleFromFeatureWidget())),r((()=>[this.selectedFeatureWidget?.viewModel?.content,this.selectedFeatureWidget?.viewModel?.state]),(()=>this._setContentFromFeatureWidget())),a((()=>!this.collapsed),(()=>{"xsmall"===this.viewModel?.view?.widthBreakpoint&&this.viewModel.active&&this.collapseEnabled&&this.viewModel.centerAtLocation()})),l((()=>this.viewModel?.allActions),"change",(()=>this._watchActions())),r((()=>this.viewModel?.allActions),(()=>this._watchActions()),c),r((()=>this.viewModel?.featureViewModels),(()=>this._featureMenuViewportScrollTop()))])}destroy(){this._destroySelectedFeatureWidget(),this._destroySpinner(),this._handles?.destroy(),this._unobserveFeatureMenuObserver(),this._featureMenuIntersectionObserver?.disconnect(),this._handles=null}get actionsMenuId(){return`${this.id}-actions-menu`}get actionsMenuButtonId(){return`${this.id}-actions-menu-button`}get featureMenuId(){return`${this.id}-feature-menu`}get titleId(){return`${this.id}-popup-title`}get contentId(){return`${this.id}-popup-content`}get hasContent(){return!!(this.selectedFeatureWidget?this.selectedFeatureWidget?.viewModel?.waitingForContent||"error"===this.selectedFeatureWidget?.viewModel?.state||this.selectedFeatureWidget?.viewModel?.content:this.viewModel?.content)}get featureNavigationVisible(){return this.viewModel.active&&this.viewModel.featureCount>1&&this.visibleElements.featureNavigation}get collapsible(){return!!(this.collapseEnabled&&this.viewModel.title&&this.hasContent)}get featureMenuVisible(){return this.featureNavigationVisible&&this.featureMenuOpen}get contentCollapsed(){return this.collapsible&&!this.featureMenuVisible&&this.collapsed}get dividedActions(){return this._divideActions()}set actionsMenuOpen(e){this._set("actionsMenuOpen",!!e)}get actionsMenuOpen(){return!!this.viewModel.active&&this._get("actionsMenuOpen")}get currentAlignment(){return this._getCurrentAlignment()}get currentDockPosition(){return this._getCurrentDockPosition()}get dockOptions(){return this._get("dockOptions")||E}set dockOptions(e){const t={...E},i=this.get("viewModel.view.breakpoints"),o={};i&&(o.width=i.xsmall,o.height=i.xsmall);const n={...t,...e},s={...t.breakpoint,...o},{breakpoint:r}=n;!0===r?n.breakpoint=s:"object"==typeof r&&(n.breakpoint={...s,...r}),this._set("dockOptions",n),this._setCurrentDockPosition(),this.reposition()}get selectedFeatureWidget(){const{_feature:e,visibleElements:t,headingLevel:i}=this,{selectedFeatureViewModel:o}=this.viewModel,n={...t,title:!1};return o?(e?(e.viewModel=o,e.visibleElements=n):this._feature=new f({headingLevel:i+1,viewModel:o,visibleElements:n}),this._feature):null}castVisibleElements(e){return{...U,...e}}blur(){const{active:e}=this.viewModel;e||V.warn("Popup can only be blurred when currently active."),this.visibleElements.closeButton?this._blurClose=!0:this._blurContainer=!0,this.scheduleRender()}clear(){this.viewModel.clear()}close(){this.visible=!1}fetchFeatures(e,t){return this.viewModel.fetchFeatures(e,t)}focus(){const{active:e}=this.viewModel;e||V.warn("Popup can only be focused when currently active."),this.visibleElements.closeButton?this._focusClose=!0:this._focusContainer=!0,this.scheduleRender()}next(){return this.viewModel.next()}open(e){this._handles.remove(N);const t=!!e&&!!e.featureMenuOpen,i=!!e&&!!e.actionsMenuOpen,o={collapsed:!!e&&!!e.collapsed,actionsMenuOpen:i,featureMenuOpen:t};"xsmall"===this.viewModel?.view?.widthBreakpoint&&(o.collapsed=!0),this.set(o),this.viewModel.open(e),this._shouldFocus(e),this._addSelectedFeatureIndexHandle()}previous(){return this.viewModel.previous()}reposition(){this.renderNow(),this._positionContainer(),this._setCurrentAlignment()}triggerAction(e){this.viewModel.triggerAction(e)}render(){const{actionsMenuOpen:e,dockEnabled:t,featureMenuVisible:i,dividedActions:o,currentAlignment:n,currentDockPosition:s}=this,{active:r}=this.viewModel,{menuActions:a}=o,l=r&&a.length>1&&e,u=r&&t,c=r&&!t,d=this.selectedFeature?.layer?.title,p=this.selectedFeature?.layer?.id,h={[D.alignTopCenter]:"top-center"===n,[D.alignBottomCenter]:"bottom-center"===n,[D.alignTopLeft]:"top-left"===n,[D.alignBottomLeft]:"bottom-left"===n,[D.alignTopRight]:"top-right"===n,[D.alignBottomRight]:"bottom-right"===n,[D.isDocked]:u,[D.shadow]:c,[D.isDockedTopLeft]:"top-left"===s,[D.isDockedTopCenter]:"top-center"===s,[D.isDockedTopRight]:"top-right"===s,[D.isDockedBottomLeft]:"bottom-left"===s,[D.isDockedBottomCenter]:"bottom-center"===s,[D.isDockedBottomRight]:"bottom-right"===s,[D.isFeatureMenuOpen]:i,[D.isActionsMenuOpen]:l};return C("div",{class:this.classes(D.base,h),role:"presentation","data-layer-title":d,"data-layer-id":p,bind:this,afterCreate:this._positionContainer,afterUpdate:this._positionContainer},r?[this.renderMainContainer(),this.renderPointer()]:null)}renderLoadingIcon(){return C("span",{"aria-hidden":"true",class:this.classes(D.icon,D.iconLoading,D.rotating)})}renderNavigationLoading(){const{messagesCommon:e}=this;return this.viewModel.pendingPromisesCount?C("div",{key:L("loading-container"),role:"presentation",class:D.loadingContainer,"aria-label":e.loading,title:e.loading},this.renderLoadingIcon()):null}renderPreviousIcon(){const e=F(this.container),t={[D.iconRightTriangleArrow]:e,[D.paginationPreviousIconRTL]:e,[D.iconLeftTriangleArrow]:!e,[D.paginationPreviousIconLTR]:!e};return C("span",{"aria-hidden":"true",class:this.classes(D.icon,t)})}renderPreviousButton(){const{messages:e}=this;return C("div",{role:"button",tabIndex:0,bind:this,onclick:this._previous,onkeydown:this._previous,class:this.classes(D.button,D.paginationPrevious),"aria-label":e.previous,title:e.previous},this.renderPreviousIcon())}renderNextIcon(){const e=F(this.container),t={[D.iconLeftTriangleArrow]:e,[D.paginationNextIconRTL]:e,[D.iconRightTriangleArrow]:!e,[D.paginationNextIconLTR]:!e};return C("span",{"aria-hidden":"true",class:this.classes(D.icon,t)})}renderNextButton(){const{messages:e}=this;return C("div",{role:"button",tabIndex:0,bind:this,onclick:this._next,onkeydown:this._next,class:this.classes(D.button,D.paginationNext),"aria-label":e.next,title:e.next},this.renderNextIcon())}renderFeatureMenuButton(){const{featureMenuOpen:e,featureMenuId:t,messagesCommon:i}=this,{featureCount:o,selectedFeatureIndex:n}=this.viewModel;return C("div",{role:"button",tabIndex:0,bind:this,onclick:this._toggleFeatureMenu,onkeydown:this._toggleFeatureMenu,afterCreate:this._focusFeatureMenuButtonNode,afterUpdate:this._focusFeatureMenuButtonNode,class:this.classes(D.button,D.featureMenuButton),"aria-haspopup":"true","aria-controls":t,"aria-expanded":e.toString(),"aria-label":i.menu,title:i.menu},this._getPageText(o,n))}renderNavigationButtons(){return this.featureNavigationVisible?[this.renderPreviousButton(),this.renderNavigationLoading()||this.renderFeatureMenuButton(),this.renderNextButton()]:null}renderDockIcon(){const{dockEnabled:e}=this,t=this._wouldDockTo(),i={[D.iconUndock]:e,[D.iconDock]:!e,[D.iconDockToRight]:!e&&("top-right"===t||"bottom-right"===t),[D.iconDockToLeft]:!e&&("top-left"===t||"bottom-left"===t),[D.iconDockToTop]:!e&&"top-center"===t,[D.iconDockToBottom]:!e&&"bottom-center"===t};return C("span",{"aria-hidden":"true",class:this.classes(i,D.icon)})}renderDockButton(){const{dockEnabled:e,messages:t}=this,i=this.viewModel?.view?.widthBreakpoint,o=e?t.undock:t.dock;return"xsmall"!==i&&this.dockOptions?.buttonEnabled?C("div",{role:"button","aria-label":o,title:o,tabIndex:0,bind:this,onclick:this._toggleDockEnabled,onkeydown:this._toggleDockEnabled,afterCreate:this._focusDockButtonNode,afterUpdate:this._focusDockButtonNode,class:this.classes(D.button,D.buttonDock)},this.renderDockIcon()):null}renderTitle(){const{title:e}=this.viewModel,{titleId:t,collapsible:i,contentCollapsed:o,messagesCommon:n}=this,s={[D.headerContainerButton]:i},r=C(w,{level:this.headingLevel,class:D.headerTitle,innerHTML:e}),a=i?C("button",{key:`${e}--collapsible`,id:t,title:o?n.expand:n.collapse,bind:this,enterAnimation:this._createFeatureUpdatedAnimation(),class:this.classes(D.headerContainer,s),"aria-expanded":o?"false":"true",onclick:this._toggleCollapsed,type:"button"},r):C("div",{key:e,id:t,bind:this,enterAnimation:this._createFeatureUpdatedAnimation(),class:this.classes(D.headerContainer,s)},r);return e?a:null}renderCloseIcon(){return C("span",{"aria-hidden":"true",class:this.classes(D.icon,D.iconClose)})}renderCloseButton(){const{visibleElements:e,messagesCommon:t}=this;return e.closeButton?C("div",{role:"button",tabIndex:0,bind:this,onclick:this._close,onkeydown:this._close,class:D.button,"aria-label":t.close,title:t.close,afterCreate:this._closeButtonNodeUpdated,afterUpdate:this._closeButtonNodeUpdated},this.renderCloseIcon()):null}renderHeader(){return C("header",{class:D.header},this.renderTitle(),C("div",{class:D.headerButtons},this.renderDockButton(),this.renderCloseButton()))}renderContentContainer(){const{contentId:e,hasContent:t,contentCollapsed:i}=this,{content:o}=this.viewModel;return t&&!i?C("article",{key:o,enterAnimation:this._createFeatureUpdatedAnimation(),id:e,class:D.content},this.renderContent()):null}renderActionsMenuButton(){const{actionsMenuId:e,actionsMenuButtonId:t,actionsMenuOpen:i,dividedActions:o,messagesCommon:n}=this,s=i?n.close:n.open,{menuActions:r}=o;return r.length?C("div",{key:L("actions-menu-button"),class:this.classes(D.button,D.actionsMenuButton),role:"button",id:t,"aria-haspopup":"true","aria-controls":i?e:null,tabIndex:0,bind:this,onclick:this._toggleActionsMenu,onkeydown:this._toggleActionsMenu,afterCreate:this._focusActionsMenuButtonNode,afterUpdate:this._focusActionsMenuButtonNode,"aria-label":s,title:s},C("span",{"aria-hidden":"true",class:D.iconActionsMenu})):null}renderMenuActions(){const{actionsMenuId:e,actionsMenuButtonId:t,actionsMenuOpen:i,dividedActions:o}=this,{menuActions:n}=o;return n.length&&i?C("ul",{id:e,role:"menu","aria-labelledby":t,key:L("actions"),class:D.actions,bind:this,onkeyup:this._handleActionMenuKeyup,afterCreate:this._actionsMenuNodeUpdated,afterUpdate:this._actionsMenuNodeUpdated},n.toArray().map((e=>this.renderAction({action:e,type:"menu-item"})))):null}renderInlineActions(){const{inlineActions:e}=this.dividedActions;return!!e.length&&e.toArray().map((e=>this.renderAction({action:e,type:"inline"})))}renderInlineActionsContainer(){const{inlineActions:e,menuActions:t}=this.dividedActions,i=!!e.length,o=!!t.length;return i||o?C("div",{key:"inline-actions-container","data-inline-actions":i.toString(),"data-menu-actions":o.toString(),class:D.inlineActionsContainer},this.renderInlineActions(),this.renderActionsMenuButton(),this.renderMenuActions()):null}renderNavigation(){return this.featureNavigationVisible?C("section",{key:L("navigation"),class:this.classes(D.navigation)},this.renderNavigationButtons()):null}renderFooter(){const{featureNavigationVisible:e,dividedActions:t}=this,{inlineActions:i,menuActions:o}=t,n=!!i.length,s=!!o.length,r={[D.footerHasPagination]:e,[D.footerHasActions]:n,[D.footerHasActionsMenu]:s};return e||n?C("div",{key:L("feature-buttons"),class:this.classes(D.footer,r)},this.renderInlineActionsContainer(),this.renderNavigation()):null}renderFeatureMenuContainer(){const{messages:e}=this,{featureViewModels:t,isLoadingFeature:i}=this.viewModel,o=x(e.selectedFeatures,{total:t.length});return C("section",{key:L("menu"),class:D.featureMenu},C("strong",{class:D.featureMenuHeader},o),C("nav",{bind:this,class:D.featureMenuViewport,"data-node-ref":"_featureMenuViewportNode",afterCreate:I},this.renderFeatureMenu(),C("div",{class:D.featureMenuObserver,bind:this,afterCreate:this._featureMenuIntersectionObserverCreated}),i?C("div",{class:D.featureMenuLoader},this.renderLoadingIcon()):null))}renderPointer(){return this.dockEnabled?null:C("div",{key:L("pointer"),class:D.pointer,role:"presentation"},C("div",{class:this.classes(D.pointerDirection,D.shadow)}))}renderMainContainer(){const{dockEnabled:e,currentAlignment:t,currentDockPosition:i,titleId:o,contentId:n,collapsible:s,hasContent:r,contentCollapsed:a,visibleElements:l}=this,{title:u}=this.viewModel,c="bottom-left"===t||"bottom-center"===t||"bottom-right"===t||"top-left"===i||"top-center"===i||"top-right"===i,d="top-left"===t||"top-center"===t||"top-right"===t||"bottom-left"===i||"bottom-center"===i||"bottom-right"===i,p={[D.shadow]:e,[D.isCollapsible]:s,[D.isCollapsed]:a};return C("div",{class:this.classes(D.main,D.widget,p),tabIndex:l.closeButton?null:-1,role:"dialog","aria-labelledby":u?o:"","aria-describedby":r&&!a?n:"",bind:this,onkeyup:this._handleMainKeyup,afterCreate:this._mainContainerNodeUpdated,afterUpdate:this._mainContainerNodeUpdated},c?this.renderFooter():null,c?this.renderFeatureMenuContainer():null,this.renderHeader(),this.renderContentContainer(),d?this.renderFooter():null,d?this.renderFeatureMenuContainer():null)}renderContent(){const e=this.viewModel?.content;return e?"string"==typeof e?C("div",{key:e,innerHTML:e}):this.renderNodeContent(e):null}renderActionText(e){return C("span",{key:"text",class:D.actionText},e)}renderActionIcon(e){const t=this._getActionClass(e),i=this._getActionImage(e),o={[D.iconLoading]:e.active,[D.rotating]:e.active,[D.icon]:!!t,[D.actionImage]:!e.active&&!!i};return t&&(o[t]=!e.active),C("span",{key:"icon","aria-hidden":"true",class:this.classes(D.icon,o),styles:this._getIconStyles(i)})}renderAction(e){const{action:t,type:i}=e,o=this._getActionTitle(t),n={[D.action]:"toggle"!==t.type,[D.actionToggle]:"toggle"===t.type,[D.actionToggleOn]:"toggle"===t.type&&t.value,[D.buttonDisabled]:t.disabled},s=[this.renderActionIcon(t),this.renderActionText(o)],r="menu-item"===i?C("li",{key:t.uid,role:"menuitem",tabIndex:0,title:o,"aria-label":o,class:this.classes(D.button,n),onkeyup:this._handleActionMenuItemKeyup,bind:this,"data-action-uid":t.uid,onclick:this._triggerAction,onkeydown:this._triggerAction},s):C("div",{key:t.uid,role:"button",tabIndex:0,title:o,"aria-label":o,class:this.classes(D.button,n),onkeyup:this._handleActionMenuItemKeyup,bind:this,"data-action-uid":t.uid,onclick:this._triggerAction,onkeydown:this._triggerAction},s);return t.visible?r:null}renderFeatureMenuItem(e,t){const{messages:i,messagesCommon:o}=this,{selectedFeatureIndex:n,selectedFeatureViewModel:s}=this.viewModel,r=e===s,a={[D.featureMenuSelected]:r},l=r?C("span",{key:L(`feature-menu-selected-feature-${n}`),title:i.selectedFeature,"aria-label":i.selectedFeature,class:D.iconCheckMark}):null,u=C("span",{innerHTML:e.title||o.untitled});return C("li",{role:"menuitem",tabIndex:-1,key:L(`feature-menu-feature-${n}`),class:this.classes(a,D.featureMenuItem),bind:this,"data-feature-index":t,onblur:this._removeActiveFeature,onfocus:this._setActiveFeature,onkeyup:this._handleFeatureMenuItemKeyup,onclick:this._selectFeature,onkeydown:this._selectFeature,onmouseover:this._setActiveFeature,onmouseleave:this._removeActiveFeature},C("span",{class:D.featureMenuTitle},u,l))}renderFeatureMenu(){const{featureMenuId:e}=this,{featureViewModels:t}=this.viewModel;return t.length>1?C("ol",{class:D.featureMenuList,id:e,bind:this,afterCreate:this._featureMenuNodeUpdated,afterUpdate:this._featureMenuNodeUpdated,onkeyup:this._handleFeatureMenuKeyup,role:"menu"},t.filter((e=>!!e.graphic)).map(((e,t)=>this.renderFeatureMenuItem(e,t)))):null}_getActionTitle(e){const{messages:t,selectedFeature:i,messagesCommon:o}=this,{id:n}=e,s=i?.attributes,r="zoom-to-feature"===n?x(e.title,{messages:t}):"remove-selected-feature"===n?x(e.title,{messages:o}):"zoom-to-clustered-features"===n||"browse-clustered-features"===n?x(e.title,{messages:t}):e.title;return r&&s?x(r,s):r}_getActionClass(e){const{selectedFeature:t}=this,i=t?.attributes,{className:o,image:n}=e,s=n||o?o:D.iconDefaultAction;return s&&i?x(s,i):s}_getActionImage(e){const{selectedFeature:t}=this,i=t?.attributes,{image:o}=e;return o&&i?x(o,i):o}_createFeatureUpdatedAnimation(){return O("enter",D.hasFeatureUpdated)}_getInlineActionCount(){const{maxInlineActions:e,featureNavigationVisible:t}=this;if("number"!=typeof e)return null;const i=Math.round(e);return Math.max(t?i-1:i,0)}_watchActions(){const{allActions:e}=this.viewModel;this.notifyChange("dividedActions");const t="actions";this._handles.remove(t),e&&e.forEach((e=>{this._handles.add(r((()=>[e.uid,e.active,e.className,e.disabled,e.id,e.title,e.image,e.visible]),(()=>this.scheduleRender())),t)}))}_divideActions(){const{allActions:e}=this.viewModel,i=e.filter((e=>e.visible)),o=this._getInlineActionCount(),n=null===o,s=0===o;return{inlineActions:n?i.slice(0):s?new t:i.slice(0,o),menuActions:n?new t:s?i.slice(0):i.slice(o)}}_featureMenuOpenChanged(e){e?this._focusFirstFeature=!0:this._focusFeatureMenuButton=!0}_actionsMenuOpenChanged(e){e?this._focusFirstAction=!0:this._focusActionsMenuButton=!0}_setTitleFromFeatureWidget(){const{selectedFeatureWidget:e,messagesCommon:t}=this;e&&(this.viewModel.title="error"===e.viewModel?.state?t.errorMessage:e.viewModel?.title||"")}_setContentFromFeatureWidget(){const{selectedFeatureWidget:e}=this;e&&(this.viewModel.content=e)}_unobserveFeatureMenuObserver(){this._featureMenuIntersectionObserverNode&&this._featureMenuIntersectionObserver.unobserve(this._featureMenuIntersectionObserverNode)}_featureMenuIntersectionObserverCreated(e){this._unobserveFeatureMenuObserver(),this._featureMenuIntersectionObserver.observe(e),this._featureMenuIntersectionObserverNode=e}_handleFeatureMenuKeyup(e){"Escape"===i(e)&&(e.stopPropagation(),this._focusFeatureMenuButton=!0,this.featureMenuOpen=!1,this.scheduleRender())}_handleActionMenuKeyup(e){"Escape"===i(e)&&(e.stopPropagation(),this._focusActionsMenuButton=!0,this.actionsMenuOpen=!1,this.scheduleRender())}_setActiveFeature(e){const{viewModel:t}=this,i=e.currentTarget["data-feature-index"];t.activeFeature=t.features[i]||null}_removeActiveFeature(){this.viewModel.activeFeature=null}_handleFeatureMenuItemKeyup(e){const t=i(e),{_featureMenuNode:o}=this,n=e.currentTarget["data-feature-index"];if(!o)return;const s=o.querySelectorAll("li"),r=s.length;if("ArrowUp"!==t)if("ArrowDown"!==t)if("Home"!==t)if("End"!==t);else{e.stopPropagation();s[s.length-1].focus()}else{e.stopPropagation();s[0].focus()}else{e.stopPropagation();s[(n+1+r)%r].focus()}else{e.stopPropagation();s[(n-1+r)%r].focus()}}_handleActionMenuItemKeyup(e){const t=i(e),{_actionsMenuNode:o}=this,n=e.currentTarget.dataset.actionUid,{menuActions:s}=this.dividedActions,r=s.findIndex((e=>e.uid===n));if(!o)return;const a=o.querySelectorAll("li"),l=a.length;if("ArrowUp"!==t)if("ArrowDown"!==t)if("Home"!==t)if("End"!==t);else{e.stopPropagation();a[a.length-1].focus()}else{e.stopPropagation();a[0].focus()}else{e.stopPropagation();a[(r+1+l)%l].focus()}else{e.stopPropagation();a[(r-1+l)%l].focus()}}_handleMainKeyup(e){const t=i(e);"ArrowLeft"===t&&(e.stopPropagation(),this.previous()),"ArrowRight"===t&&(e.stopPropagation(),this.next())}_spinnerEnabledChange(e){if(this._destroySpinner(),!e)return;const t=this.get("viewModel.view");this._createSpinner(t)}_hideSpinner(){const{_spinner:e}=this;e&&(e.location=null,e.hide())}_displaySpinner(){const{_spinner:e}=this;if(!e)return;const{location:t,waitingForResult:i}=this.viewModel;i?e.show({location:t}):e.hide()}_getIconStyles(e){return{"background-image":e?`url(${e})`:""}}async _shouldFocus(e){e.shouldFocus&&(await u((()=>!0===this.viewModel?.active)),this.focus())}_addSelectedFeatureIndexHandle(){const e=r((()=>this.viewModel?.selectedFeatureIndex),((e,t)=>this._selectedFeatureIndexUpdated(e,t)));this._handles.add(e,N)}_selectedFeatureIndexUpdated(e,t){const{featureCount:i}=this;i&&e!==t&&-1!==e&&(this.actionsMenuOpen=!1,this.featureMenuOpen=!1)}_destroySelectedFeatureWidget(){const{_feature:e}=this;e&&(e.viewModel=null,e&&!e.destroyed&&e.destroy()),this._feature=null}_isScreenLocationWithinView(e,t){return e.x>-1&&e.y>-1&&e.x<=t.width&&e.y<=t.height}_isOutsideView(e){const{popupHeight:t,popupWidth:i,screenLocation:o,side:n,view:s}=e;if(isNaN(i)||isNaN(t)||!s||!o)return!1;const r=s.padding;return"right"===n&&o.x+i/2>s.width-r.right||("left"===n&&o.x-i/2<r.left||("top"===n&&o.y-t<r.top||"bottom"===n&&o.y+t>s.height-r.bottom))}_calculateAutoAlignment(e){if("auto"!==e)return e;const{_pointerOffsetInPx:t,_containerNode:i,_mainContainerNode:o,viewModel:n}=this,{screenLocation:r,view:a}=n;if(s(r)||!a||!i)return"top-center";if(!this._isScreenLocationWithinView(r,a))return this._get("currentAlignment")||"top-center";function l(e){return parseInt(e.replace(/[^-\d\.]/g,""),10)}const u=o?window.getComputedStyle(o,null):null,c=u?l(u.getPropertyValue("max-height")):0,d=u?l(u.getPropertyValue("height")):0,{height:p,width:h}=i.getBoundingClientRect(),g=h+t,_=Math.max(p,c,d)+t,f=this._isOutsideView({popupHeight:_,popupWidth:g,screenLocation:r,side:"right",view:a}),v=this._isOutsideView({popupHeight:_,popupWidth:g,screenLocation:r,side:"left",view:a}),m=this._isOutsideView({popupHeight:_,popupWidth:g,screenLocation:r,side:"top",view:a}),b=this._isOutsideView({popupHeight:_,popupWidth:g,screenLocation:r,side:"bottom",view:a});return v?m?"bottom-right":"top-right":f?m?"bottom-left":"top-left":m?b?"top-center":"bottom-center":"top-center"}_callCurrentAlignment(e){return"function"==typeof e?e.call(this):e}_getCurrentAlignment(){const{alignment:e,dockEnabled:t}=this;return t||!this.viewModel.active?null:this._calculatePositionResult(this._calculateAutoAlignment(this._callCurrentAlignment(e)))}_setCurrentAlignment(){this._set("currentAlignment",this._getCurrentAlignment())}_setCurrentDockPosition(){this._set("currentDockPosition",this._getCurrentDockPosition())}_calculatePositionResult(e){const t=["left","right"];return F(this.container)&&t.reverse(),e.replace(/leading/gi,t[0]).replace(/trailing/gi,t[1])}_callDockPosition(e){return"function"==typeof e?e.call(this):e}_getDockPosition(){return this._calculatePositionResult(this._calculateAutoDockPosition(this._callDockPosition(this.dockOptions?.position)))}_getCurrentDockPosition(){return this.dockEnabled&&this.viewModel.active?this._getDockPosition():null}_wouldDockTo(){return this.dockEnabled?null:this._getDockPosition()}_calculateAutoDockPosition(e){if("auto"!==e)return e;const t=this.viewModel?.view,i=F(this.container)?"top-left":"top-right";if(!t)return i;const o=t.padding||{left:0,right:0,top:0,bottom:0},n=t.width-o.left-o.right,{breakpoints:s}=t;return s&&n<=s.xsmall?"bottom-center":i}_positionContainer(e=this._containerNode){if(e&&(this._containerNode=e),!e)return;const{screenLocation:t}=this.viewModel,{width:i}=e.getBoundingClientRect(),o=this._calculatePositionStyle(t,i);o&&(e.style.top=o.top,e.style.left=o.left,e.style.bottom=o.bottom,e.style.right=o.right)}_calculateFullWidth(e){const{currentAlignment:t,_pointerOffsetInPx:i}=this;return"top-left"===t||"bottom-left"===t||"top-right"===t||"bottom-right"===t?e+i:e}_calculateAlignmentPosition(e,t,i,o){const{currentAlignment:n,_pointerOffsetInPx:s}=this,r=o/2,a=i.height-t,l=i.width-e,{padding:u}=this.view;return"bottom-center"===n?{top:t+s-u.top,left:e-r-u.left}:"top-left"===n?{bottom:a+s-u.bottom,right:l+s-u.right}:"bottom-left"===n?{top:t+s-u.top,right:l+s-u.right}:"top-right"===n?{bottom:a+s-u.bottom,left:e+s-u.left}:"bottom-right"===n?{top:t+s-u.top,left:e+s-u.left}:"top-center"===n?{bottom:a+s-u.bottom,left:e-r-u.left}:void 0}_calculatePositionStyle(e,t){const{dockEnabled:i,view:o}=this;if(!o)return;if(i)return{left:"",top:"",right:"",bottom:""};if(s(e)||!t)return;const n=this._calculateFullWidth(t),r=this._calculateAlignmentPosition(e.x,e.y,o,n);return r?{top:void 0!==r.top?`${r.top}px`:"auto",left:void 0!==r.left?`${r.left}px`:"auto",bottom:void 0!==r.bottom?`${r.bottom}px`:"auto",right:void 0!==r.right?`${r.right}px`:"auto"}:void 0}_viewChange(e,t){e&&t&&(this.close(),this.clear())}_viewReadyChange(e,t){if(e){const e=this.get("viewModel.view");this._wireUpView(e)}else t&&(this.close(),this.clear())}_wireUpView(e){if(this._destroySpinner(),!e)return;const{spinnerEnabled:t}=this;t&&this._createSpinner(e),this._setDockEnabledForViewSize(this.dockOptions)}_dockingThresholdCrossed(e,t,i){const[o,n]=e,[s,r]=t,{width:a,height:l}=i;return o<=a&&s>a||o>a&&s<=a||n<=l&&r>l||n>l&&r<=l}_updateDockEnabledForViewSize(e,t){if(!e||!t)return;const i=this.get("viewModel.view.padding")||{left:0,right:0,top:0,bottom:0},o=i.left+i.right,n=i.top+i.bottom,s=[],r=[];s[0]=e[0]-o,s[1]=e[1]-n,r[0]=t[0]-o,r[1]=t[1]-n;const{dockOptions:a}=this,l=a.breakpoint;this._dockingThresholdCrossed(s,r,l)&&this._setDockEnabledForViewSize(a),this._setCurrentDockPosition()}_focusDockButtonNode(e){this._focusDockButton&&(this._focusDockButton=!1,e.focus())}_closeButtonNodeUpdated(e){return this._focusClose?(this._focusClose=!1,void e.focus()):this._blurClose?(this._blurClose=!1,void e.blur()):void 0}_mainContainerNodeUpdated(e){return this._mainContainerNode=e,this._focusContainer?(this._focusContainer=!1,void e.focus()):this._blurContainer?(this._blurContainer=!1,void e.blur()):void 0}_featureMenuNodeUpdated(e){if(this._featureMenuNode=e,!e||!this._focusFirstFeature)return;this._focusFirstFeature=!1;const t=e.querySelectorAll("li");if(t.length){t[0].focus()}}_actionsMenuNodeUpdated(e){if(this._actionsMenuNode=e,!e||!this._focusFirstAction)return;this._focusFirstAction=!1;const t=e.querySelectorAll("li");if(t.length){t[0].focus()}}_focusFeatureMenuButtonNode(e){this._focusFeatureMenuButton&&(this._focusFeatureMenuButton=!1,e.focus())}_focusActionsMenuButtonNode(e){this._focusActionsMenuButton&&(this._focusActionsMenuButton=!1,e.focus())}_featureMenuViewportScrollTop(){this._featureMenuViewportNode&&(this._featureMenuViewportNode.scrollTop=0)}_toggleScreenLocationEnabled(){const{dockEnabled:e,viewModel:t}=this;if(!t)return;const i=t.active&&!e;t.screenLocationEnabled=i}_shouldDockAtCurrentViewSize(e){const t=e.breakpoint,i=this.viewModel?.view?.ui;if(!i)return!1;const{width:o,height:n}=i;if(isNaN(o)||isNaN(n))return!1;const s=t.hasOwnProperty("width")&&o<=t.width,r=t.hasOwnProperty("height")&&n<=t.height;return s||r}_setDockEnabledForViewSize(e){e.breakpoint&&(this.dockEnabled=this._shouldDockAtCurrentViewSize(e))}_getPageText(e,t){return this.featureNavigationVisible?x(this.messages.pageText,{index:t+1,total:e}):null}_destroySpinner(){const{_spinner:e,view:t}=this;e&&(t&&t.ui&&t.ui.remove(this._spinner,B),e.destroy(),this._spinner=null)}_createSpinner(e){e&&(this._spinner=new v({view:e}),e.ui.add(this._spinner,{key:B,position:"manual"}))}_toggleCollapsed(){this.collapsed=!this.collapsed}_close(){this.close(),this.view&&this.view.focus()}_toggleDockEnabled(){this.dockEnabled=!this.dockEnabled,this._focusDockButton=!0,this.scheduleRender()}_toggleFeatureMenu(){const e=!this.featureMenuOpen;this._featureMenuOpenChanged(e),this.actionsMenuOpen=!1,this.featureMenuOpen=e}_toggleActionsMenu(){const e=!this.actionsMenuOpen;this._actionsMenuOpenChanged(e),this.featureMenuOpen=!1,this.actionsMenuOpen=e}_triggerAction(e){const t=e.currentTarget.dataset.actionUid,{allActions:i}=this.viewModel,o=i.findIndex((e=>e.uid===t)),n=i.getItemAt(o);n&&"toggle"===n.type&&(n.value=!n.value),this.actionsMenuOpen=!1,this.viewModel.triggerAction(o)}_selectFeature(e){const t=e.currentTarget["data-feature-index"];isNaN(t)||(this.viewModel.selectedFeatureIndex=t),this.featureMenuOpen=!1,this._focusFeatureMenuButton=!0,this.scheduleRender()}_next(){this.next()}_previous(){this.previous()}};e([g({readOnly:!0})],R.prototype,"actionsMenuId",null),e([g({readOnly:!0})],R.prototype,"actionsMenuButtonId",null),e([g({readOnly:!0})],R.prototype,"featureMenuId",null),e([g({readOnly:!0})],R.prototype,"titleId",null),e([g({readOnly:!0})],R.prototype,"contentId",null),e([g({readOnly:!0})],R.prototype,"hasContent",null),e([g({readOnly:!0})],R.prototype,"featureNavigationVisible",null),e([g({readOnly:!0})],R.prototype,"collapsible",null),e([g({readOnly:!0})],R.prototype,"featureMenuVisible",null),e([g({readOnly:!0})],R.prototype,"contentCollapsed",null),e([g({readOnly:!0})],R.prototype,"dividedActions",null),e([p("viewModel.actions")],R.prototype,"actions",void 0),e([g()],R.prototype,"actionsMenuOpen",null),e([g()],R.prototype,"alignment",void 0),e([p("viewModel.autoCloseEnabled")],R.prototype,"autoCloseEnabled",void 0),e([p("viewModel.autoOpenEnabled")],R.prototype,"autoOpenEnabled",void 0),e([p("viewModel.defaultPopupTemplateEnabled")],R.prototype,"defaultPopupTemplateEnabled",void 0),e([p("viewModel.content")],R.prototype,"content",void 0),e([g()],R.prototype,"collapsed",void 0),e([g()],R.prototype,"collapseEnabled",void 0),e([g({readOnly:!0})],R.prototype,"currentAlignment",null),e([g({readOnly:!0})],R.prototype,"currentDockPosition",null),e([g()],R.prototype,"dockOptions",null),e([g()],R.prototype,"dockEnabled",void 0),e([p("viewModel.featureCount")],R.prototype,"featureCount",void 0),e([g()],R.prototype,"featureMenuOpen",void 0),e([p("viewModel.features")],R.prototype,"features",void 0),e([p("viewModel.goToOverride")],R.prototype,"goToOverride",void 0),e([g()],R.prototype,"headingLevel",void 0),e([p("viewModel.highlightEnabled")],R.prototype,"highlightEnabled",void 0),e([p("viewModel.location")],R.prototype,"location",void 0),e([g({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],R.prototype,"label",void 0),e([g()],R.prototype,"maxInlineActions",void 0),e([g(),k("esri/widgets/Popup/t9n/Popup")],R.prototype,"messages",void 0),e([g(),k("esri/t9n/common")],R.prototype,"messagesCommon",void 0),e([p("viewModel.promises")],R.prototype,"promises",void 0),e([p("viewModel.selectedFeature")],R.prototype,"selectedFeature",void 0),e([p("viewModel.selectedFeatureIndex")],R.prototype,"selectedFeatureIndex",void 0),e([g({readOnly:!0})],R.prototype,"selectedFeatureWidget",null),e([g()],R.prototype,"spinnerEnabled",void 0),e([p("viewModel.title")],R.prototype,"title",void 0),e([p("viewModel.updateLocationEnabled")],R.prototype,"updateLocationEnabled",void 0),e([p("viewModel.view")],R.prototype,"view",void 0),e([g({type:M}),A(["triggerAction","trigger-action"])],R.prototype,"viewModel",void 0),e([p("viewModel.visible")],R.prototype,"visible",void 0),e([g()],R.prototype,"visibleElements",void 0),e([h("visibleElements")],R.prototype,"castVisibleElements",null),e([y()],R.prototype,"_close",null),e([y()],R.prototype,"_toggleDockEnabled",null),e([y()],R.prototype,"_toggleFeatureMenu",null),e([y()],R.prototype,"_toggleActionsMenu",null),e([y()],R.prototype,"_triggerAction",null),e([y()],R.prototype,"_selectFeature",null),e([y()],R.prototype,"_next",null),e([y()],R.prototype,"_previous",null),R=e([_(S)],R);const j=R;export{j as default};