UNPKG

gantt-source_management

Version:

Gantt, Schedule,

13 lines 7.23 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((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.37.5 * @released 2024-07-19 * @license SEE LICENSE IN LICENSE FILE */const e="chart-timeline-grid-row-cell",i="chart-timeline-items-row-item";function a(t={}){const e={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},movement:{x:0,y:0},events:{down:null,move:null,up:null}};return t.captureEvents&&(e.captureEvents=Object.assign(Object.assign({},e.captureEvents),t.captureEvents)),e}const s="TimelinePointer",n=`config.plugin.${s}`;class o{constructor(t,s){this.locked={up:!1,move:!1,down:!1},this.initialScrollPosPx={horizontal:0,vertical:0},this.onDestroy=[],this.classNames={cell:"",item:""},this.api=s.api,this.state=s.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=s.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.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=a(t),this.classNames.cell=this.api.getClass(e),this.classNames.item=this.api.getClass(i),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)))}destroy(){this.onDestroy.forEach((t=>t())),this.element.removeEventListener("pointerdown",this.pointerDown),document.removeEventListener("pointerup",this.pointerUp),document.removeEventListener("pointermove",this.pointerMove),this.api.pluginDestroyed(s)}updateData(){this.state.update(n,(()=>Object.assign({},this.data)))}apiLock(t,e=!0){this.locked[t]=e}apiUnlock(t){this.locked[t]=!1}apiIsLocked(t){return this.locked[t]}apiAddPointerListener(t,e){this.apiPointerListeners[t].add(e)}apiRemovePointerListener(t,e){this.apiPointerListeners[t].delete(e)}apiTriggerPointerListener(t,e){this.apiPointerListeners[t].forEach((t=>t(e)))}getRealTarget(t){let a=t.target.closest("."+this.classNames.item);return a||(a=t.target.closest("."+this.classNames.cell),a||(a=t.target.closest(`[data-type="${i}"]`),a||(a=t.target.closest(`[data-type="${e}"]`),a||null)))}getRealPosition(t){const e={x:0,y:0};if(this.element){const i=this.element.getBoundingClientRect();e.x=t.clientX-i.x,e.y=t.clientY-i.y;const a=this.state.get("$data.scroll.vertical.preciseOffset")||0;e.y-=a}return e}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.data.pointerState="down",this.data.currentTarget=t.target;const a=this.getRealTarget(t);if(this.data.realTarget=a,this.data.targetType="",this.data.targetData=null,this.data.realTarget)if(this.data.realTarget.classList.contains(this.classNames.item))this.data.targetType=i,this.data.targetData=this.data.realTarget.vido.item;else if(this.data.realTarget.classList.contains(this.classNames.cell))this.data.targetType=e,this.data.targetData=this.data.realTarget.vido;else if(this.data.realTarget.dataset.type===i){this.data.targetType=i;const t=this.data.realTarget.dataset.gstcid;this.data.targetData=this.api.getItem(t)}else if(this.data.realTarget.dataset.type===e){this.data.targetType=e;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 s=this.getRealPosition(t);this.data.initialPosition=s,this.data.currentPosition=s;const n={type:this.data.pointerState,originalEvent:t,targetElement:a,targetData:this.data.targetData,targetType:this.data.targetType,initialPosition:this.data.initialPosition,currentPosition:this.data.currentPosition,movement:{x:0,y:0},initialScrollPosPx:this.initialScrollPosPx,isMoving:this.data.isMoving,allEvents:this.data.events};this.apiTriggerPointerListener("down",n),this.updateData()}pointerUp(t){if(!this.data.enabled)return;this.data.pointerState="up",this.data.isMoving=!1,this.data.events.up=t,this.data.currentPosition=this.getRealPosition(t);const e={type:this.data.pointerState,originalEvent:t,targetElement:this.data.realTarget,targetData:this.data.targetData,targetType:this.data.targetType,initialPosition:this.data.initialPosition,currentPosition:this.data.currentPosition,movement:this.data.movement,initialScrollPosPx:this.initialScrollPosPx,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 e=this.state.get("$data.scroll.horizontal.handlePosPx");this.data.pointerState="move",this.data.events.move=t,this.data.currentPosition=this.getRealPosition(t),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+=e-this.initialScrollPosPx.horizontal;const i={type:this.data.pointerState,originalEvent:t,targetElement:this.data.realTarget,targetData:this.data.targetData,targetType:this.data.targetType,initialPosition:this.data.initialPosition,currentPosition:this.data.currentPosition,movement:this.data.movement,initialScrollPosPx:this.initialScrollPosPx,isMoving:this.data.isMoving,allEvents:this.data.events};this.apiTriggerPointerListener("move",i),this.updateData()}}t.CELL=e,t.ITEM=i,t.Plugin=function(t={}){return function(e){const i=e.api,s=e.api.mergeDeep,r=e.state.get(n);r&&(t=s(s({},t),r));const h=a(t);e.state.update(n,h);const l=new o(t,e);return i.pluginInitialized("TimelinePointer"),l.destroy}},Object.defineProperty(t,"__esModule",{value:!0})}));