UNPKG

gantt-schedule-timeline-calendar

Version:

Gantt, Schedule, Timeline, Calendar components all in one. [gantt, timeline, schedule, scheduler, calendar, booking, gantt chart, reservation, javascript gantt, javascript timeline, javascript schedule, javascript scheduler, javascript calendar, javascrip

13 lines 3.04 kB
/** * CalendarScroll plugin * * @copyright NEURONET - Rafal Pospiech * @author Rafal Pospiech <neuronet.io@gmail.com> * @module gantt-schedule-timeline-calendar * @link https://github.com/neuronetio/gantt-schedule-timeline-calendar * @link https://gantt-schedule-timeline-calendar.neuronet.io * @version 3.43.14 * @released 2026-06-11 * @license SEE LICENSE IN LICENSE FILE */ const t={enabled:!0,bodyClassName:["gstc-scrolling","gstc-cursor-grabbing"]};function e(e=t){let i,n,o,s=e.enabled;class a{constructor(t){this.moving=!1,this.initialDataIndex={x:0,y:0},this.pointerDown=this.pointerDown.bind(this),this.pointerUp=this.pointerUp.bind(this),this.destroy=this.destroy.bind(this),this.pointerMove=i.schedule(this.pointerMove.bind(this)),t.addEventListener("pointerdown",this.pointerDown),document.addEventListener("pointermove",this.pointerMove,{passive:!0}),document.addEventListener("pointerup",this.pointerUp),t.style.cursor="grab"}destroy(t){t.removeEventListener("pointerdown",this.pointerDown),document.removeEventListener("pointermove",this.pointerMove),document.removeEventListener("pointerup",this.pointerUp)}resetInitialPoint(t){this.initialPoint={x:t.screenX,y:t.screenY}}pointerDown(t){if(!s)return;e.bodyClassName&&(Array.isArray(e.bodyClassName)?document.body.classList.add(...e.bodyClassName):document.body.classList.add(e.bodyClassName)),this.moving=!0,this.resetInitialPoint(t);const i=o.get("$data.scroll");this.initialDataIndex={x:i.horizontal.dataIndex||0,y:i.vertical.dataIndex||0}}pointerUp(){s&&(e.bodyClassName&&(Array.isArray(e.bodyClassName)?document.body.classList.remove(...e.bodyClassName):document.body.classList.remove(e.bodyClassName)),this.moving&&(this.moving=!1))}handleHorizontalMovement(t,e){const i=o.get("$data.chart.time"),s=o.get("config.scroll.horizontal");if(t.x>0){if(0===this.initialDataIndex.x)return this.resetInitialPoint(e);const o=i.allDates[i.level];let a,r=this.initialDataIndex.x-1,l=0;for(;r>0&&(a=o[r],l+=a.width,!(l>=t.x));r--);let d=0;a&&(d=a.leftPx),s.byPixels?n.setScrollLeft(d):n.setScrollLeft(r)}else if(t.x<0){let a=this.initialDataIndex.x;const r=o.get("$data.scroll.horizontal"),l=i.allDates[i.level];if(a-1>=l.length-r.lastPageCount)return this.resetInitialPoint(e);let d,c=0;for(let e=l.length;a<e&&(d=l[a],c+=d.width,!(-c<=t.x));a++);if(a-1>=l.length-r.lastPageCount)return;let h=0;d&&(h=d.leftPx),s.byPixels?n.setScrollLeft(h):n.setScrollLeft(a)}}pointerMove(t){if(!s||!this.moving)return;const e={x:t.screenX-this.initialPoint.x,y:t.screenY-this.initialPoint.y};this.handleHorizontalMovement(e,t)}}return function(t){i=t,n=i.api,o=i.state;const r="config.plugin.CalendarScroll",l=t.state.get(r);return l&&(e=n.mergeDeep({},e,l)),o.update(r,e),o.subscribe("config.plugin.CalendarScroll.enabled",t=>s=t),o.update("config.actions.chart-calendar",t=>(t.push(a),t)),n.pluginInitialized("CalendarScroll"),function(){o.update("config.actions.chart-calendar",t=>t.filter(t=>t!==a)),n.pluginDestroyed("CalendarScroll")}}}export{e as Plugin};