Files
wdi-dashboard/node_modules/@chakra-ui/menu/dist/chunk-BWUXSGSJ.mjs.map
2024-08-16 15:06:52 +05:30

1 line
2.3 KiB
Plaintext

{"version":3,"sources":["../src/get-next-item-from-search.ts"],"sourcesContent":["/**\n * Gets the next item based on a search string\n *\n * @param items array of items\n * @param searchString the search string\n * @param itemToString resolves an item to string\n * @param currentItem the current selected item\n */\nexport function getNextItemFromSearch<T>(\n items: T[],\n searchString: string,\n itemToString: (item: T) => string,\n currentItem: T,\n): T | undefined {\n if (searchString == null) {\n return currentItem\n }\n\n // If current item doesn't exist, find the item that matches the search string\n if (!currentItem) {\n const foundItem = items.find((item) =>\n itemToString(item).toLowerCase().startsWith(searchString.toLowerCase()),\n )\n return foundItem\n }\n\n // Filter items for ones that match the search string (case insensitive)\n const matchingItems = items.filter((item) =>\n itemToString(item).toLowerCase().startsWith(searchString.toLowerCase()),\n )\n\n // If there's a match, let's get the next item to select\n if (matchingItems.length > 0) {\n let nextIndex: number\n\n // If the currentItem is in the available items, we move to the next available option\n if (matchingItems.includes(currentItem)) {\n const currentIndex = matchingItems.indexOf(currentItem)\n nextIndex = currentIndex + 1\n if (nextIndex === matchingItems.length) {\n nextIndex = 0\n }\n return matchingItems[nextIndex]\n }\n // Else, we pick the first item in the available items\n nextIndex = items.indexOf(matchingItems[0])\n return items[nextIndex]\n }\n\n // a decent fallback to the currentItem\n return currentItem\n}\n"],"mappings":";;;AAQO,SAAS,sBACd,OACA,cACA,cACA,aACe;AACf,MAAI,gBAAgB,MAAM;AACxB,WAAO;AAAA,EACT;AAGA,MAAI,CAAC,aAAa;AAChB,UAAM,YAAY,MAAM;AAAA,MAAK,CAAC,SAC5B,aAAa,IAAI,EAAE,YAAY,EAAE,WAAW,aAAa,YAAY,CAAC;AAAA,IACxE;AACA,WAAO;AAAA,EACT;AAGA,QAAM,gBAAgB,MAAM;AAAA,IAAO,CAAC,SAClC,aAAa,IAAI,EAAE,YAAY,EAAE,WAAW,aAAa,YAAY,CAAC;AAAA,EACxE;AAGA,MAAI,cAAc,SAAS,GAAG;AAC5B,QAAI;AAGJ,QAAI,cAAc,SAAS,WAAW,GAAG;AACvC,YAAM,eAAe,cAAc,QAAQ,WAAW;AACtD,kBAAY,eAAe;AAC3B,UAAI,cAAc,cAAc,QAAQ;AACtC,oBAAY;AAAA,MACd;AACA,aAAO,cAAc,SAAS;AAAA,IAChC;AAEA,gBAAY,MAAM,QAAQ,cAAc,CAAC,CAAC;AAC1C,WAAO,MAAM,SAAS;AAAA,EACxB;AAGA,SAAO;AACT;","names":[]}