UNPKG

vue-gantt-3

Version:

A gantt component for Vue 3

1 lines 3.47 kB
{"version":3,"file":"useTableScroll.mjs","sources":["../../../../src/components/tableView/useTableScroll.ts"],"sourcesContent":["import { ref, onBeforeUnmount } from 'vue';\nimport type { Ref } from 'vue';\n\nexport const useTableScroll = ({\n tableBodyView,\n tableBodyVerticalScrollViewport,\n emitTriggerGanttViewScroll\n}: {\n tableBodyView: Ref<HTMLDivElement | null>,\n tableBodyVerticalScrollViewport: Ref<HTMLDivElement | null>,\n emitTriggerGanttViewScroll: (options: ScrollToOptions) => void\n}) => {\n const scrollFromGanttView = ref(false);\n\n onBeforeUnmount(() => {\n tableBodyView.value?.removeEventListener('wheel', bodyWheel);\n tableBodyVerticalScrollViewport.value?.removeEventListener('scroll', verticalScrollViewportScroll);\n });\n\n /**\n * per scroll will trigger this function\n * @returns\n */\n const verticalScrollViewportScroll = () => {\n if (scrollFromGanttView.value) {\n scrollFromGanttView.value = false;\n } else {\n emitTriggerGanttViewScroll({ top: tableBodyVerticalScrollViewport.value?.scrollTop });\n }\n };\n\n /**\n * prevent scroll default to keep scrolling consistent with gantt view,\n * The disadvantage is that it will scroll directly to the specified position, and the intermediate scrolling process cannot be seen\n * @param e\n * @returns\n */\n const bodyWheel = (e: WheelEvent) => {\n e.preventDefault();\n if (!tableBodyVerticalScrollViewport.value) return;\n if (Math.abs(e.deltaY) < 3) return;\n scrollFromGanttView.value = false;\n const scrollSpeed = 100;\n const scrollDistance = e.deltaY > 0 ? scrollSpeed : -scrollSpeed;\n const scrollTop = tableBodyVerticalScrollViewport.value?.scrollTop + scrollDistance;\n tableBodyVerticalScrollViewport.value?.scrollTo({ top: scrollTop });\n };\n\n const scrollTo = (options: ScrollToOptions, onWheel?: boolean) => {\n scrollFromGanttView.value = true;\n\n if (onWheel) {\n tableBodyVerticalScrollViewport.value?.scrollTo(options);\n } else {\n tableBodyVerticalScrollViewport.value?.scrollTo(options);\n // if the new options value is consistent with the current scrollbar position, the scroll event will not be triggered again,\n // and you need to manually set scrollFromTableBody to false\n if (tableBodyVerticalScrollViewport.value?.scrollTop === options.top) {\n scrollFromGanttView.value = false;\n }\n }\n };\n\n return {\n scrollTo,\n bodyWheel,\n verticalScrollViewportScroll\n };\n};"],"names":[],"mappings":";AAGO,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AACF,MAIM;AACE,QAAA,sBAAsB,IAAI,KAAK;AAErC,kBAAgB,MAAM;;AACN,wBAAA,UAAA,mBAAO,oBAAoB,SAAS;AAClB,0CAAA,UAAA,mBAAO,oBAAoB,UAAU;AAAA,EAA4B,CAClG;AAMD,QAAM,+BAA+B,MAAM;;AACzC,QAAI,oBAAoB,OAAO;AAC7B,0BAAoB,QAAQ;AAAA,IAAA,OACvB;AACL,iCAA2B,EAAE,MAAK,qCAAgC,UAAhC,mBAAuC,WAAW;AAAA,IAAA;AAAA,EAExF;AAQM,QAAA,YAAY,CAAC,MAAkB;;AACnC,MAAE,eAAe;AACb,QAAA,CAAC,gCAAgC,MAAO;AAC5C,QAAI,KAAK,IAAI,EAAE,MAAM,IAAI,EAAG;AAC5B,wBAAoB,QAAQ;AAC5B,UAAM,cAAc;AACpB,UAAM,iBAAiB,EAAE,SAAS,IAAI,cAAc;AAC9C,UAAA,cAAY,qCAAgC,UAAhC,mBAAuC,aAAY;AACrE,0CAAgC,UAAhC,mBAAuC,SAAS,EAAE,KAAK;EACzD;AAEM,QAAA,WAAW,CAAC,SAA0B,YAAsB;;AAChE,wBAAoB,QAAQ;AAE5B,QAAI,SAAS;AACqB,4CAAA,UAAA,mBAAO,SAAS;AAAA,IAAO,OAClD;AAC2B,4CAAA,UAAA,mBAAO,SAAS;AAGhD,YAAI,qCAAgC,UAAhC,mBAAuC,eAAc,QAAQ,KAAK;AACpE,4BAAoB,QAAQ;AAAA,MAAA;AAAA,IAC9B;AAAA,EAEJ;AAEO,SAAA;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}