All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.lib.components.VSelect.useScrolling.mjs.map Maven / Gradle / Ivy

{"version":3,"file":"useScrolling.mjs","names":["shallowRef","watch","useScrolling","listRef","textFieldRef","isScrolling","scrollTimeout","onListScroll","e","cancelAnimationFrame","value","requestAnimationFrame","finishScrolling","Promise","resolve","stop","onListKeydown","key","focus","includes","el","$el","scrollTo","top","scrollHeight","behavior","children","querySelectorAll","getBoundingClientRect","child","bottom","reverse"],"sources":["../../../src/components/VSelect/useScrolling.ts"],"sourcesContent":["// Utilities\nimport { shallowRef, watch } from 'vue'\n\n// Types\nimport type { Ref } from 'vue'\nimport type { VList } from '@/components/VList'\nimport type { VTextField } from '@/components/VTextField'\n\nexport function useScrolling (listRef: Ref, textFieldRef: Ref) {\n  const isScrolling = shallowRef(false)\n  let scrollTimeout: number\n  function onListScroll (e: Event) {\n    cancelAnimationFrame(scrollTimeout)\n    isScrolling.value = true\n    scrollTimeout = requestAnimationFrame(() => {\n      scrollTimeout = requestAnimationFrame(() => {\n        isScrolling.value = false\n      })\n    })\n  }\n  async function finishScrolling () {\n    await new Promise(resolve => requestAnimationFrame(resolve))\n    await new Promise(resolve => requestAnimationFrame(resolve))\n    await new Promise(resolve => requestAnimationFrame(resolve))\n    await new Promise(resolve => {\n      if (isScrolling.value) {\n        const stop = watch(isScrolling, () => {\n          stop()\n          resolve()\n        })\n      } else resolve()\n    })\n  }\n  async function onListKeydown (e: KeyboardEvent) {\n    if (e.key === 'Tab') {\n      textFieldRef.value?.focus()\n    }\n\n    if (!['PageDown', 'PageUp', 'Home', 'End'].includes(e.key)) return\n    const el: HTMLElement = listRef.value?.$el\n    if (!el) return\n\n    if (e.key === 'Home' || e.key === 'End') {\n      el.scrollTo({\n        top: e.key === 'Home' ? 0 : el.scrollHeight,\n        behavior: 'smooth',\n      })\n    }\n\n    await finishScrolling()\n\n    const children = el.querySelectorAll(':scope > :not(.v-virtual-scroll__spacer)')\n\n    if (e.key === 'PageDown' || e.key === 'Home') {\n      const top = el.getBoundingClientRect().top\n      for (const child of children) {\n        if (child.getBoundingClientRect().top >= top) {\n          (child as HTMLElement).focus()\n          break\n        }\n      }\n    } else {\n      const bottom = el.getBoundingClientRect().bottom\n      for (const child of [...children].reverse()) {\n        if (child.getBoundingClientRect().bottom <= bottom) {\n          (child as HTMLElement).focus()\n          break\n        }\n      }\n    }\n  }\n\n  return { onListScroll, onListKeydown }\n}\n"],"mappings":"AAAA;AACA,SAASA,UAAU,EAAEC,KAAK,QAAQ,KAAK;;AAEvC;;AAKA,OAAO,SAASC,YAAYA,CAAEC,OAA+B,EAAEC,YAAyC,EAAE;EACxG,MAAMC,WAAW,GAAGL,UAAU,CAAC,KAAK,CAAC;EACrC,IAAIM,aAAqB;EACzB,SAASC,YAAYA,CAAEC,CAAQ,EAAE;IAC/BC,oBAAoB,CAACH,aAAa,CAAC;IACnCD,WAAW,CAACK,KAAK,GAAG,IAAI;IACxBJ,aAAa,GAAGK,qBAAqB,CAAC,MAAM;MAC1CL,aAAa,GAAGK,qBAAqB,CAAC,MAAM;QAC1CN,WAAW,CAACK,KAAK,GAAG,KAAK;MAC3B,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;EACA,eAAeE,eAAeA,CAAA,EAAI;IAChC,MAAM,IAAIC,OAAO,CAACC,OAAO,IAAIH,qBAAqB,CAACG,OAAO,CAAC,CAAC;IAC5D,MAAM,IAAID,OAAO,CAACC,OAAO,IAAIH,qBAAqB,CAACG,OAAO,CAAC,CAAC;IAC5D,MAAM,IAAID,OAAO,CAACC,OAAO,IAAIH,qBAAqB,CAACG,OAAO,CAAC,CAAC;IAC5D,MAAM,IAAID,OAAO,CAAOC,OAAO,IAAI;MACjC,IAAIT,WAAW,CAACK,KAAK,EAAE;QACrB,MAAMK,IAAI,GAAGd,KAAK,CAACI,WAAW,EAAE,MAAM;UACpCU,IAAI,CAAC,CAAC;UACND,OAAO,CAAC,CAAC;QACX,CAAC,CAAC;MACJ,CAAC,MAAM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