UNPKG

mira-app-server

Version:

Mira Server - standalone server application using mira-app-core

2 lines (1 loc) 1.04 kB
const F=["INPUT","TEXTAREA"];function v(r,n,t,i={}){if(!n||i.enableIgnoredElement&&F.includes(n.nodeName))return null;const{arrowKeyOptions:e="both",attributeName:l="[data-reka-collection-item]",itemsArray:f=[],loop:o=!0,dir:g="ltr",preventScroll:k=!0,focus:x=!1}=i,[s,w,N,h,A,b]=[r.key==="ArrowRight",r.key==="ArrowLeft",r.key==="ArrowUp",r.key==="ArrowDown",r.key==="Home",r.key==="End"],u=N||h,c=s||w;if(!A&&!b&&(!u&&!c||e==="vertical"&&c||e==="horizontal"&&u))return null;const d=t?Array.from(t.querySelectorAll(l)):f;if(!d.length)return null;k&&r.preventDefault();let a=null;return c||u?a=y(d,n,{goForward:u?h:g==="ltr"?s:w,loop:o}):A?a=d.at(0)||null:b&&(a=d.at(-1)||null),x&&a?.focus(),a}function y(r,n,t,i=r.includes(n)?r.length:r.length+1){if(--i===0)return null;const e=r.indexOf(n);let l;if(e===-1?l=t.goForward?0:r.length-1:l=t.goForward?e+1:e-1,!t.loop&&(l<0||l>=r.length))return null;const f=(l+r.length)%r.length,o=r[f];return o?o.hasAttribute("disabled")&&o.getAttribute("disabled")!=="false"?y(r,o,t,i):o:null}export{v as u};