UNPKG

siegel

Version:

Web application development ecosystem

1 lines 678 B
import e from"../../../common/is/exists/index.js";import*as t from"./key_codes.js";export default function(r,o){let{selectStore:i,keyCode:n,options:d,selectedOptionIndex:s}=r,{onDelete:f,onEnter:l}=o,[a,c]=i,{arrowSelectIndex:m}=a,u=n==t.UP;u||n==t.DOWN?(a.arrowSelectIndex=function(t){let{options:r,selectedOptionIndex:o,arrowSelectIndex:i,isUp:n}=t,{length:d}=r,s=d-1,f=n?-1:1,l=new Set([]),a=e(i)?i+f:n?s:0;a=a<0?s:a>s?0:a;for(let e=a;0<=e&&e<d;e+=f){if(e!=o&&!r[e].disabled)return e;if(l.add(e),n?0==e&&(e=s):e==s&&(e=-1),l.size==s)return}}({options:d,selectedOptionIndex:s,arrowSelectIndex:m,isUp:u}),e(a.arrowSelectIndex)&&c({...a})):n==t.DELETE?f():e(m)&&n==t.ENTER&&l()}