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 • 9.13 kB
JavaScript
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).TimelinePointer={})}(this,function(t){"use strict";
/**
* TimelinePointer 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 i="chart-timeline-grid-row-cell",e="chart-timeline-items-row-item";function s(t={}){const i={enabled:!0,isMoving:!1,pointerState:"up",currentTarget:null,realTarget:null,targetType:"",targetData:null,captureEvents:{down:!1,up:!1,move:!1},initialPosition:{x:0,y:0},currentPosition:{x:0,y:0},initialPositionOrigin:{x:0,y:0},currentPositionOrigin:{x:0,y:0},movement:{x:0,y:0},events:{down:null,move:null,up:null}};return t.captureEvents&&(i.captureEvents=Object.assign(Object.assign({},i.captureEvents),t.captureEvents)),i}const a="TimelinePointer",n=`config.plugin.${a}`;class o{constructor(t,a){this.locked={up:!1,move:!1,down:!1},this.initialScrollPosPx={horizontal:0,vertical:0},this.initialScrollOffset={top:0,left:0},this.onDestroy=[],this.classNames={cell:"",item:""},this.api=a.api,this.state=a.state,this.apiPointerListeners={down:new Set,move:new Set,up:new Set},this.pointerDown=this.pointerDown.bind(this),this.pointerMove=this.pointerMove.bind(this),this.pointerMove=a.schedule(this.pointerMove),this.pointerUp=this.pointerUp.bind(this),this.onDestroy.push(this.state.subscribe("$data.elements.chart-timeline",t=>{t&&(this.element=t,this.updateElementClass(),this.element.removeEventListener("pointerdown",this.pointerDown),this.element.addEventListener("pointerdown",this.pointerDown),document.removeEventListener("pointerup",this.pointerUp),document.addEventListener("pointerup",this.pointerUp),document.removeEventListener("pointermove",this.pointerMove),document.addEventListener("pointermove",this.pointerMove))})),this.apiLock=this.apiLock.bind(this),this.apiUnlock=this.apiUnlock.bind(this),this.apiIsLocked=this.apiIsLocked.bind(this),this.apiAddPointerListener=this.apiAddPointerListener.bind(this),this.apiRemovePointerListener=this.apiRemovePointerListener.bind(this),this.getRealPosition=this.getRealPosition.bind(this),this.data=s(t),this.classNames.cell=this.api.getClass(i),this.classNames.item=this.api.getClass(e),this.destroy=this.destroy.bind(this),this.api.plugins.TimelinePointer={lock:this.apiLock,unlock:this.apiUnlock,isLocked:this.apiIsLocked,addPointerListener:this.apiAddPointerListener,removePointerListener:this.apiRemovePointerListener},this.onDestroy.push(this.state.subscribe(n,t=>{this.data=t,this.updateElementClass()}))}destroy(){this.onDestroy.forEach(t=>t()),this.element.removeEventListener("pointerdown",this.pointerDown),document.removeEventListener("pointerup",this.pointerUp),document.removeEventListener("pointermove",this.pointerMove),this.element&&(this.element.classList.contains("gstc-touch-action-none")&&this.element.classList.remove("gstc-touch-action-none"),this.element.classList.contains("gstc-touch-action-auto")||this.element.classList.remove("gstc-touch-action-auto")),this.api.pluginDestroyed(a)}updateElementClass(){this.element&&(this.data.enabled?(this.element.classList.contains("gstc-touch-action-auto")&&this.element.classList.remove("gstc-touch-action-auto"),this.element.classList.add("gstc-touch-action-none")):(this.element.classList.contains("gstc-touch-action-none")&&this.element.classList.remove("gstc-touch-action-none"),this.element.classList.add("gstc-touch-action-auto")))}updateData(){this.state.update(n,()=>Object.assign({},this.data))}apiLock(t,i=!0){this.locked[t]=i}apiUnlock(t){this.locked[t]=!1}apiIsLocked(t){return this.locked[t]}apiAddPointerListener(t,i){this.apiPointerListeners[t].add(i)}apiRemovePointerListener(t,i){this.apiPointerListeners[t].delete(i)}apiTriggerPointerListener(t,i){this.apiPointerListeners[t].forEach(t=>t(i))}getRealTarget(t){let s=t.target.closest("."+this.classNames.item);return s||(s=t.target.closest("."+this.classNames.cell),s||(s=t.target.closest(`[data-type="${e}"]`),s||(s=t.target.closest(`[data-type="${i}"]`),s||null)))}getCoordinatesRelativeToParent(t){let i=t.offsetLeft,e=t.offsetTop,s=t.offsetParent;for(;null!==s;)i+=s.offsetLeft,e+=s.offsetTop,s=s.offsetParent;return{x:i,y:e}}getRealPosition(t){const i={x:0,y:0};if(this.element){const e=this.getCoordinatesRelativeToParent(this.element);i.x=t.pageX-e.x,i.y=t.pageY-e.y}return i}compensateOffset(t){t=Object.assign({},t);const i=this.state.get("$data.scroll").vertical.preciseOffset||0;return t.y-=i,t}pointerDown(t){if(!this.data.enabled)return;this.initialScrollPosPx.horizontal=this.state.get("$data.scroll.horizontal.handlePosPx"),this.initialScrollPosPx.vertical=this.state.get("$data.scroll.vertical.handlePosPx"),this.initialScrollOffset.top=this.state.get("$data.scroll.vertical.preciseOffset")||0,this.initialScrollOffset.left=this.state.get("$data.scroll.horizontal.preciseOffset")||0,this.data.pointerState="down",this.data.currentTarget=t.target;const s=this.getRealTarget(t);if(this.data.realTarget=s,this.data.targetType="",this.data.targetData=null,this.data.realTarget)if(this.data.realTarget.classList.contains(this.classNames.item))this.data.targetType=e,this.data.targetData=this.data.realTarget.vido.item;else if(this.data.realTarget.classList.contains(this.classNames.cell))this.data.targetType=i,this.data.targetData=this.data.realTarget.vido;else if(this.data.realTarget.dataset.type===e){this.data.targetType=e;const t=this.data.realTarget.dataset.gstcid;this.data.targetData=this.api.getItem(t)}else if(this.data.realTarget.dataset.type===i){this.data.targetType=i;const t=this.data.realTarget.dataset.gstcid;this.data.targetData=this.state.get(`$data.chart.grid.cells.${t}`)}this.data.isMoving=!!this.data.targetType,this.data.events.down=t,this.data.events.move=t;const a=this.getRealPosition(t);this.data.initialPositionOrigin=a,this.data.currentPositionOrigin=a;const n=this.compensateOffset(a);this.data.initialPosition=n,this.data.currentPosition=n;const o={type:this.data.pointerState,originalEvent:t,targetElement:s,targetData:this.data.targetData,targetType:this.data.targetType,initialPosition:this.data.initialPosition,currentPosition:this.data.currentPosition,initialPositionOrigin:this.data.initialPositionOrigin,currentPositionOrigin:this.data.currentPositionOrigin,movement:{x:0,y:0},initialScrollPosPx:this.initialScrollPosPx,initialScrollOffset:this.initialScrollOffset,isMoving:this.data.isMoving,allEvents:this.data.events};this.apiTriggerPointerListener("down",o),this.updateData()}pointerUp(t){if(!this.data.enabled)return;this.data.pointerState="up",this.data.isMoving=!1,this.data.events.up=t;const i=this.getRealPosition(t);this.data.currentPositionOrigin=i,this.data.currentPosition=this.compensateOffset(i);const e={type:this.data.pointerState,originalEvent:t,targetElement:this.data.realTarget,targetData:this.data.targetData,targetType:this.data.targetType,initialPositionOrigin:this.data.initialPositionOrigin,currentPositionOrigin:this.data.currentPositionOrigin,initialPosition:this.data.initialPosition,currentPosition:this.data.currentPosition,movement:this.data.movement,initialScrollPosPx:this.initialScrollPosPx,initialScrollOffset:this.initialScrollOffset,isMoving:this.data.isMoving,allEvents:this.data.events};this.apiTriggerPointerListener("up",e),this.data.realTarget=null,this.data.targetData=null,this.updateData()}pointerMove(t){if(!this.data.enabled||!this.data.isMoving)return;const i=this.state.get("$data.scroll.horizontal.handlePosPx");this.data.pointerState="move",this.data.events.move=t,this.data.currentPositionOrigin=this.getRealPosition(t),this.data.currentPosition=this.compensateOffset(this.data.currentPositionOrigin),this.data.movement.x=this.data.currentPosition.x-this.data.initialPosition.x,this.data.movement.y=this.data.currentPosition.y-this.data.initialPosition.y,this.data.movement.x+=i-this.initialScrollPosPx.horizontal;const e={type:this.data.pointerState,originalEvent:t,targetElement:this.data.realTarget,targetData:this.data.targetData,targetType:this.data.targetType,initialPositionOrigin:this.data.initialPositionOrigin,currentPositionOrigin:this.data.currentPositionOrigin,initialPosition:this.data.initialPosition,currentPosition:this.data.currentPosition,movement:this.data.movement,initialScrollPosPx:this.initialScrollPosPx,initialScrollOffset:this.initialScrollOffset,isMoving:this.data.isMoving,allEvents:this.data.events};this.apiTriggerPointerListener("move",e),this.updateData()}}t.CELL=i,t.ITEM=e,t.Plugin=function(t={}){return function(i){const e=i.api,a=i.api.mergeDeep,r=i.state.get(n);r&&(t=a(a({},t),r));const l=s(t);i.state.update(n,l);const h=new o(t,i);return e.pluginInitialized("TimelinePointer"),h.destroy}},Object.defineProperty(t,"__esModule",{value:!0})});