package.dist.prod.features.F6Navigation.js Maven / Gradle / Ivy
"use strict";import{registerFeature as a}from"../FeaturesRegistry.js";import{isF6Next as r,isF6Previous as l}from"../Keys.js";import{instanceOfUI5Element as u}from"../UI5Element.js";import{getFirstFocusableElement as h}from"../util/FocusableElements.js";import m from"../util/getFastNavigationGroups.js";import p from"../util/isElementClickable.js";class n{constructor(){this.selectedGroup=null;this.groups=[];this.keydownHandler=this._keydownHandler.bind(this),this.attachEventListeners()}attachEventListeners(){document.addEventListener("keydown",this.keydownHandler)}async groupElementToFocus(e){const o=u(e)?e.getDomRef():e;if(o){if(p(o))return o;const t=await h(o);if(t)return t}}async findNextFocusableGroupElement(e){let o;for(let t=0;t-1?e+1>=this.groups.length?(e=0,s=this.groups[e]):(e+=1,s=this.groups[e]):(e=0,s=this.groups[e]),o=await this.groupElementToFocus(s),o)break}return o}async findPreviousFocusableGroupElement(e){let o;for(let t=0;t0?(e=await this.groupElementToFocus(this.groups[e-1])===await this.groupElementToFocus(this.groups[e])?e-2:e-1,e<0&&(e=this.groups.length-1),s=this.groups[e]):(e=this.groups.length-1,s=this.groups[e]),o=await this.groupElementToFocus(s),o)break}return o}async _keydownHandler(e){const o=r(e),t=l(e);if(!(o||t)||(this.updateGroups(),this.groups.length<1))return;e.preventDefault();let s;if(this.groups.length===0)return s=await this.groupElementToFocus(this.groups[0]),s?.focus();let i=-1;this.selectedGroup&&(i=this.groups.indexOf(this.selectedGroup)),o&&(s=await this.findNextFocusableGroupElement(i)),t&&(s=await this.findPreviousFocusableGroupElement(i)),s?.focus()}removeEventListeners(){document.removeEventListener("keydown",this.keydownHandler)}updateGroups(){this.setSelectedGroup(),this.groups=m(document.body)}setSelectedGroup(e=window.document){const o=window.document.querySelector("html");let t=this.deepActive(e);for(;t&&t.getAttribute("data-sap-ui-fastnavgroup")!=="true"&&t!==o;)t=t.parentElement?t.parentNode:t.parentNode.host;this.selectedGroup=t}deepActive(e){return e?.activeElement?.shadowRoot?.activeElement?this.deepActive(e.activeElement.shadowRoot):e.activeElement}destroy(){this.removeEventListeners()}static init(){return this._instance||(this._instance=new n),this._instance}}a("F6Navigation",n);export default n;
//# sourceMappingURL=F6Navigation.js.map