Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
"use strict";import{isDown as _,isUp as d,isLeft as h,isRight as a,isHome as I,isEnd as c,isPageDown as m,isPageUp as l}from"../Keys.js";import u from"../util/getActiveElement.js";import n from"../types/NavigationMode.js";import r from"../types/ItemNavigationBehavior.js";import{instanceOfUI5Element as g}from"../UI5Element.js";class f{constructor(e,t){if(!e.isUI5Element)throw new Error("The root web component must be a UI5 Element instance");if(this.rootWebComponent=e,this.rootWebComponent.addEventListener("keydown",this._onkeydown.bind(this)),this._initBound=this._init.bind(this),this.rootWebComponent.attachComponentStateFinalized(this._initBound),typeof t.getItemsCallback!="function")throw new Error("getItemsCallback is required");this._getItems=t.getItemsCallback,this._currentIndex=t.currentIndex||0,this._rowSize=t.rowSize||1,this._behavior=t.behavior||r.Static,this._navigationMode=t.navigationMode||n.Auto,this._affectedPropertiesNames=t.affectedPropertiesNames||[],this._skipItemsSize=t.skipItemsSize||null}setCurrentItem(e){const t=this._getItems().indexOf(e);if(t===-1){console.warn("The provided item is not managed by ItemNavigation",e);return}this._currentIndex=t,this._applyTabIndex()}setRowSize(e){this._rowSize=e}_init(){this._getItems().forEach((e,t)=>{e.forcedTabIndex=t===this._currentIndex?"0":"-1"})}_onkeydown(e){if(!this._canNavigate())return;const t=this._navigationMode===n.Horizontal||this._navigationMode===n.Auto,i=this._navigationMode===n.Vertical||this._navigationMode===n.Auto,s=this.rootWebComponent.effectiveDir==="rtl";if(s&&h(e)&&t)this._handleRight();else if(s&&a(e)&&t)this._handleLeft();else if(h(e)&&t)this._handleLeft();else if(a(e)&&t)this._handleRight();else if(d(e)&&i)this._handleUp();else if(_(e)&&i)this._handleDown();else if(I(e))this._handleHome();else if(c(e))this._handleEnd();else if(l(e))this._handlePageUp();else if(m(e))this._handlePageDown();else return;e.preventDefault(),this._applyTabIndex(),this._focusCurrentItem()}_handleUp(){const e=this._getItems().length;if(this._currentIndex-this._rowSize>=0){this._currentIndex-=this._rowSize;return}if(this._behavior===r.Cyclic){const t=this._currentIndex%this._rowSize,i=t===0?this._rowSize-1:t-1,s=Math.ceil(e/this._rowSize);let o=i+(s-1)*this._rowSize;o>e-1&&(o-=this._rowSize),this._currentIndex=o}else this._currentIndex=0}_handleDown(){const e=this._getItems().length;if(this._currentIndex+this._rowSize0){this._currentIndex-=1;return}this._behavior===r.Cyclic&&(this._currentIndex=e-1)}_handleRight(){const e=this._getItems().length;if(this._currentIndex1?this._rowSize:this._getItems().length;this._currentIndex-=this._currentIndex%e}_handleEnd(){const e=this._rowSize>1?this._rowSize:this._getItems().length;this._currentIndex+=e-1-this._currentIndex%e}_handlePageUp(){this._rowSize>1||this._handlePageUpFlat()}_handlePageDown(){this._rowSize>1||this._handlePageDownFlat()}_handlePageUpFlat(){if(this._skipItemsSize===null){this._currentIndex-=this._currentIndex;return}this._currentIndex+1>this._skipItemsSize?this._currentIndex-=this._skipItemsSize:this._currentIndex-=this._currentIndex}_handlePageDownFlat(){if(this._skipItemsSize===null){this._currentIndex=this._getItems().length-1;return}this._getItems().length-this._currentIndex-1>this._skipItemsSize?this._currentIndex+=this._skipItemsSize:this._currentIndex=this._getItems().length-1}_applyTabIndex(){const e=this._getItems();for(let t=0;t{const i=this.rootWebComponent[t];this.rootWebComponent[t]=Array.isArray(i)?[...i]:{...i}})}_focusCurrentItem(){const e=this._getCurrentItem();e&&e.focus()}_canNavigate(){const e=this._getCurrentItem(),t=u();return e&&e===t}_getCurrentItem(){const e=this._getItems();if(!e.length)return;for(;this._currentIndex>=e.length;)this._currentIndex-=this._rowSize;this._currentIndex<0&&(this._currentIndex=0);const t=e[this._currentIndex];if(!t)return;if(g(t))return t.getFocusDomRef();const i=this.rootWebComponent.getDomRef();if(i&&t.id)return i.querySelector(`[id="${t.id}"]`)}}export default f;export{};
//# sourceMappingURL=ItemNavigation.js.map