vue-gantt-3
Version:
A gantt component for Vue 3
1 lines • 5.49 kB
Source Map (JSON)
{"version":3,"file":"useTimePoint.mjs","sources":["../../../../../../src/components/ganttView/ganttBody/ganttTimeLineView/useTimePoint.ts"],"sourcesContent":["import { inject, triggerRef } from 'vue';\nimport type { ComputedRef, ShallowRef, Ref } from 'vue';\nimport type { GanttRowNode, TimePoint, TimeLine, TimePointNode, VisibleTimeLine } from '@/types';\nimport dayjs, { Dayjs } from 'dayjs';\n\nexport const createTimePointNodes = (timeLine: TimeLine) => {\n return timeLine.timePoints?.map(timePoint => {\n return {\n date: dayjs(timePoint.date),\n id: timePoint.id,\n data: timePoint,\n icon: timePoint.icon,\n useTimePointComp: timePoint.useTimePointComp,\n translateX: 0,\n compParams: timePoint.compParams\n };\n });\n};\n\nexport const useTimePoint = ({\n timePointSize,\n perHourSpacing,\n rowNodeMap,\n visibleTimeLineMap\n}: {\n timePointSize: ComputedRef<number>,\n perHourSpacing: Ref<number>,\n rowNodeMap: Ref<Map<string, GanttRowNode>, Map<string, GanttRowNode>>,\n visibleTimeLineMap: ShallowRef<Map<string, VisibleTimeLine[]>, Map<string, VisibleTimeLine[]>>\n}) => {\n\n const timePointContextMenu = inject('timePointContextMenu') as (e: MouseEvent, timePoints: TimePoint[], rowNode?: GanttRowNode) => void;\n\n const onTimePointContextMenu = (e: MouseEvent, timeLine: VisibleTimeLine, timePoint: TimePointNode, rowId: string) => {\n const offsetX = e.offsetX;\n const diffX = offsetX - timePointSize.value / 2;\n const diffSecond = diffX / perHourSpacing.value * 60 * 60;\n const halfSeconf = timePointSize.value / 2 / perHourSpacing.value * 60 * 60;\n const clickedDate = timePoint.date.add(diffSecond, 'second');\n const minDate = clickedDate.add(-halfSeconf, 'second');\n const maxDate = clickedDate.add(halfSeconf, 'second');\n const selectedTimePoints = timeLine.timePointNodes?.filter(timePointNode => {\n return timePointNode.date.isBetween(minDate, maxDate);\n }) || [];\n const selectedTimePointsData = selectedTimePoints.map(timePointNode => timePointNode.data);\n timePointContextMenu(e, selectedTimePointsData, rowNodeMap.value.get(rowId));\n };\n\n const timePointMoveFinished = inject('timePointMoveFinished') as (timePoint: TimePoint, date: Dayjs) => void;\n\n /**\n * handle time point move\n * @param e\n * @param timeLine\n * @param timePoint\n */\n const onTimePointMouseDown = (e: MouseEvent, timeLine: VisibleTimeLine, timePoint: TimePointNode) => {\n const startX = e.clientX;\n const startTranslateX = timePoint.translateX;\n const onMouseMove = (event: MouseEvent) => {\n let currentX = event.clientX;\n const diffX = currentX - startX;\n let translateX = startTranslateX + diffX;\n if (translateX < 0) {\n translateX = 0;\n }\n if (translateX > timeLine.width) {\n translateX = timeLine.width;\n }\n timePoint.translateX = translateX;\n triggerRef(visibleTimeLineMap);\n };\n const onMouseUp = () => {\n if (timePoint.translateX !== startTranslateX) {\n const diffX = timePoint.translateX - startTranslateX;\n const diffSecond = diffX / perHourSpacing.value * 60 * 60;\n const roundOffSecond = diffX < 0 ? Math.ceil(diffSecond) : Math.floor(diffSecond);\n const newDate = timePoint.date.add(roundOffSecond, 'second');\n timePoint.date = newDate;\n timePointMoveFinished(timePoint.data, newDate);\n }\n window.removeEventListener('mousemove', onMouseMove);\n window.removeEventListener('mouseup', onMouseUp);\n };\n\n window.addEventListener('mousemove', onMouseMove);\n window.addEventListener('mouseup', onMouseUp);\n };\n return {\n onTimePointContextMenu,\n onTimePointMouseDown\n };\n};"],"names":[],"mappings":";;AAKa,MAAA,uBAAuB,CAAC,aAAuB;;AACnD,UAAA,cAAS,eAAT,mBAAqB,IAAI,CAAa,cAAA;AACpC,WAAA;AAAA,MACL,MAAM,MAAM,UAAU,IAAI;AAAA,MAC1B,IAAI,UAAU;AAAA,MACd,MAAM;AAAA,MACN,MAAM,UAAU;AAAA,MAChB,kBAAkB,UAAU;AAAA,MAC5B,YAAY;AAAA,MACZ,YAAY,UAAU;AAAA,IACxB;AAAA,EAAA;AAEJ;AAEO,MAAM,eAAe,CAAC;AAAA,EAC3B;AAAA,EACA;AAAA,EAC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