UNPKG

@progress/kendo-react-gantt

Version:

React Gantt enables the display of self-referencing tabular data with many features. KendoReact Gantt package

9 lines (8 loc) 7.06 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("react"),c=require("@progress/kendo-date-math"),k=require("@progress/kendo-react-common"),f=require("@progress/kendo-react-data-tools"),L=require("@progress/kendo-react-treelist"),u=require("../constants/index.js");function C(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const T=C(O),I=f.orderBy,Y=f.filterBy,F=k.mapTree,H=k.extendDataItem,Z=L.createDataTree,P=e=>({fields:{...u.DEFAULT_TASK_MODEL_FIELDS,...e}}),U=e=>({fields:{...u.DEFAULT_DEPENDENCY_MODEL_FIELDS,...e}}),B=e=>c.getDate(e),_=(e,t)=>c.getDate(c.addDays(e,t||1)),q=(e,t,n,o)=>n<t&&e<=o;function M(e){return new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()))}const D=4,S=10,j=(e,t,n,o)=>{const r=[];let s=0,a=0;const d=S,l=Math.floor(n/2),E=e.top<t.top,i=()=>r.push({left:a,top:s});if(o===0||o===3){const g=o===3?"start":"end";s=e.top,a=e[g],i(),a=Math[g==="start"?"min":"max"](e[g],t[g]),a=g==="start"?a-d:a+d,i(),s=t.top,i(),a=g==="start"?t[g]-D:t[g]+D,i(),h(s,a,r,g!=="start")}else{const g=o===2?"start":"end",m=o===2?"end":"start",p=o===2?e[g]-S*2>=t[m]:e[g]+S*2<=t[m];s=e.top,a=e[g],i(),a=g==="start"?a-d:a+d,i(),p||(s=E?s+l:s-l,i(),a=g==="start"?t[m]+d:t[m]-d,i()),s=t.top,i(),a=m==="start"?t[m]-D:t[m]+D,i(),h(s,a,r,m!=="start")}return r},h=(e,t,n,o)=>o?w(e,t,n):z(e,t,n),w=(e,t,n)=>{n.push({top:e-D/2,left:t}),n.push({top:e,left:t-D+1}),n.push({top:e+D/2,left:t}),n.push({top:e,left:t})},z=(e,t,n)=>{n.push({top:e+D/2,left:t}),n.push({top:e,left:t+D-1}),n.push({top:e-D/2,left:t}),n.push({top:e,left:t})},v=e=>{if(e.workWeekStart===void 0||e.workWeekEnd===void 0)return[];const t=[];let n=e.workWeekStart;for(t.push(n);e.workWeekEnd!==n;)n>6?n-=7:n++,t.push(n);return t},A=(e,t)=>{const n=e.getDay();return t.indexOf(n)>-1},y=(e,{step:t,timezone:n})=>{const o=[],r=c.ZonedDate.fromLocalDate(e.start,n),s=c.ZonedDate.fromLocalDate(e.end,n);let a=r.clone();for(;a.getTime()<s.getTime();){const d=a.clone(),l=d.clone().addTime(t),E=new Date(d.getTime()),g={end:new Date(l.getTime()),start:E,zonedStart:d,zonedEnd:l};o.push(g),a=a.addTime(t)}return o},W=(e,{timezone:t},n)=>{const o=[],r=c.ZonedDate.fromLocalDate(e.start,t),s=c.ZonedDate.fromLocalDate(e.end,t);for(let a=r.clone();a.getTime()<s.getTime();){const d=a.clone(),l=_(c.firstDayInWeek(c.getDate(d),n.firstDay()),u.DAYS_IN_WEEK_COUNT),E=c.ZonedDate.fromUTCDate(M(l),t),i=E.getTime()>s.getTime()?s.clone():E;a=i.clone();const g=new Date(d.getTime()),p={end:new Date(i.getTime()),start:g,zonedStart:d,zonedEnd:i};o.push(p)}return o},b=(e,{timezone:t})=>{const n=[],o=c.ZonedDate.fromLocalDate(e.start,t),r=c.ZonedDate.fromLocalDate(e.end,t);for(let s=o.clone();s.getTime()<r.getTime();){const a=s.clone(),d=c.ZonedDate.fromLocalDate(c.addMonths(new Date(a.getTime()),1),t);s=d.clone();const l=new Date(a.getTime()),i={end:new Date(d.getTime()),start:l,zonedStart:a,zonedEnd:d};n.push(i)}return n},R=(e,{timezone:t})=>{const n=[],o=c.ZonedDate.fromLocalDate(e.start,t),r=c.ZonedDate.fromLocalDate(e.end,t);for(let s=o.clone();s.getTime()<r.getTime();){const a=s.clone(),d=c.ZonedDate.fromLocalDate(c.addMonths(new Date(a.getTime()),12),t);s=d.clone();const l=new Date(a.getTime()),i={end:new Date(d.getTime()),start:l,zonedStart:a,zonedEnd:d};n.push(i)}return n},K=(e,t,n)=>{const o=n.parseDate(t.workDayStart).getHours(),r=n.parseDate(t.workDayEnd).getHours();return y(e,{step:c.MS_PER_MINUTE*t.slotDuration,timezone:t.timezone}).map(a=>{const d=a.zonedStart.getHours();return{range:a,isWork:d>=o&&d<r,span:1,text:n.formatDate(a.zonedStart,u.HOUR_DATE_FORMAT),type:"time"}})},$=(e,t,n)=>y(e,{step:c.MS_PER_DAY,timezone:t.timezone}).map(r=>({range:r,isWork:A(r.start,t.workDays),span:1,text:n.formatDate(r.zonedStart,u.DAY_DATE_FORMAT),type:"day"})),G=(e,t,n)=>W(e,{timezone:t.timezone},n).map(r=>{const s=Math.round((r.zonedEnd.getTime()-r.zonedStart.getTime())/c.MS_PER_DAY);return{range:r,isWork:!1,span:s,text:`${n.formatDate(r.zonedStart,u.DAY_DATE_FORMAT)} - ${n.formatDate(r.zonedEnd,u.DAY_DATE_FORMAT)}`,type:"week"}}),J=(e,t,n)=>b(e,{timezone:t.timezone}).map(r=>{const s=Math.round((r.zonedEnd.getTime()-r.zonedStart.getTime())/c.MS_PER_DAY);return{range:r,isWork:!1,span:s,text:n.formatDate(r.zonedStart,u.MONTH_DATE_FORMAT),type:"month"}}),Q=(e,t,n)=>R(e,{timezone:t.timezone}).map(r=>{const s=Math.round((r.zonedEnd.getTime()-r.zonedStart.getTime())/c.MS_PER_DAY);return{range:r,isWork:!1,span:s,text:n.formatDate(r.zonedStart,u.YEAR_DATE_FORMAT),type:"year"}}),V=(e,t,n)=>{const o=n;return T.createElement("table",{className:"k-table k-table-md",ref:t,"aria-hidden":!0},T.createElement("tbody",{className:"k-table-tbody"},e.map((r,s)=>T.createElement("tr",{className:"k-table-row",key:s},r.map((a,d)=>T.createElement("td",{key:a.range.start.getTime(),colSpan:a.span,className:k.classNames("k-table-th",{"k-header":!0,"k-nonwork-hour":!a.isWork})},o?T.createElement(o,{rowIndex:s,index:d,range:a.range,text:a.text,isWork:a.isWork,type:a.type}):a.text))))))},X=(e,t)=>{const n=e[e.length-1];return T.createElement("table",{className:"k-table k-table-md k-gantt-columns",ref:t,"aria-hidden":!0},T.createElement("tbody",{className:"k-table-tbody"},T.createElement("tr",{className:"k-table-row"},n.map(o=>T.createElement("td",{key:o.range.start.getTime(),colSpan:o.span,className:k.classNames("k-table-td",{"k-nonwork-hour":!o.isWork})})))))},ee=(e,t)=>{const n=e[e.length-1];let o=0,r=0;return n.forEach(s=>{const a=s.span;r+=a,a>o&&(o=a)}),Math.round(r*t/o)},x=(e,t)=>!!k.getter(t)(e),N=(e,t)=>!!k.getter(t)(e),te=(e,t)=>n=>x(n,e)&&N(n,t)?[...k.getter(t)(n)]:[];exports.ARROW_SIZE=D;exports.MIN_LINE_WIDTH=S;exports.addArrow=h;exports.addArrowEast=z;exports.addArrowWest=w;exports.createDataTree=Z;exports.dependencyCoordinates=j;exports.expandedChildren=te;exports.extendDataItem=H;exports.filterBy=Y;exports.getDaySlots=$;exports.getDependencyModelFields=U;exports.getEndDate=_;exports.getHourSlots=K;exports.getMonthSlots=J;exports.getStartDate=B;exports.getTaskModelFields=P;exports.getTimelineContent=X;exports.getTimelineHeader=V;exports.getTimelineWidth=ee;exports.getWeekSlots=G;exports.getWorkDays=v;exports.getYearSlots=Q;exports.hasChildren=N;exports.isExpanded=x;exports.isInRange=q;exports.isWorkDay=A;exports.mapTree=F;exports.orderBy=I;exports.toMonthRanges=b;exports.toRanges=y;exports.toUTCDateTime=M;exports.toWeekRanges=W;exports.toYearRanges=R;