UNPKG

89.7 kBJavaScriptView Raw
1import React, { useMemo, useRef, useState, useEffect } from 'react';
2
3function _extends() {
4 _extends = Object.assign || function (target) {
5 for (var i = 1; i < arguments.length; i++) {
6 var source = arguments[i];
7
8 for (var key in source) {
9 if (Object.prototype.hasOwnProperty.call(source, key)) {
10 target[key] = source[key];
11 }
12 }
13 }
14
15 return target;
16 };
17
18 return _extends.apply(this, arguments);
19}
20
21function _unsupportedIterableToArray(o, minLen) {
22 if (!o) return;
23 if (typeof o === "string") return _arrayLikeToArray(o, minLen);
24 var n = Object.prototype.toString.call(o).slice(8, -1);
25 if (n === "Object" && o.constructor) n = o.constructor.name;
26 if (n === "Map" || n === "Set") return Array.from(o);
27 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
28}
29
30function _arrayLikeToArray(arr, len) {
31 if (len == null || len > arr.length) len = arr.length;
32
33 for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
34
35 return arr2;
36}
37
38function _createForOfIteratorHelperLoose(o, allowArrayLike) {
39 var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
40 if (it) return (it = it.call(o)).next.bind(it);
41
42 if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
43 if (it) o = it;
44 var i = 0;
45 return function () {
46 if (i >= o.length) return {
47 done: true
48 };
49 return {
50 done: false,
51 value: o[i++]
52 };
53 };
54 }
55
56 throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
57}
58
59var ViewMode;
60
61(function (ViewMode) {
62 ViewMode["Hour"] = "Hour";
63 ViewMode["QuarterDay"] = "Quarter Day";
64 ViewMode["HalfDay"] = "Half Day";
65 ViewMode["Day"] = "Day";
66 ViewMode["Week"] = "Week";
67 ViewMode["Month"] = "Month";
68 ViewMode["Year"] = "Year";
69})(ViewMode || (ViewMode = {}));
70
71var intlDTCache = {};
72var getCachedDateTimeFormat = function getCachedDateTimeFormat(locString, opts) {
73 if (opts === void 0) {
74 opts = {};
75 }
76
77 var key = JSON.stringify([locString, opts]);
78 var dtf = intlDTCache[key];
79
80 if (!dtf) {
81 dtf = new Intl.DateTimeFormat(locString, opts);
82 intlDTCache[key] = dtf;
83 }
84
85 return dtf;
86};
87var addToDate = function addToDate(date, quantity, scale) {
88 var newDate = new Date(date.getFullYear() + (scale === "year" ? quantity : 0), date.getMonth() + (scale === "month" ? quantity : 0), date.getDate() + (scale === "day" ? quantity : 0), date.getHours() + (scale === "hour" ? quantity : 0), date.getMinutes() + (scale === "minute" ? quantity : 0), date.getSeconds() + (scale === "second" ? quantity : 0), date.getMilliseconds() + (scale === "millisecond" ? quantity : 0));
89 return newDate;
90};
91var startOfDate = function startOfDate(date, scale) {
92 var scores = ["millisecond", "second", "minute", "hour", "day", "month", "year"];
93
94 var shouldReset = function shouldReset(_scale) {
95 var maxScore = scores.indexOf(scale);
96 return scores.indexOf(_scale) <= maxScore;
97 };
98
99 var newDate = new Date(date.getFullYear(), shouldReset("year") ? 0 : date.getMonth(), shouldReset("month") ? 1 : date.getDate(), shouldReset("day") ? 0 : date.getHours(), shouldReset("hour") ? 0 : date.getMinutes(), shouldReset("minute") ? 0 : date.getSeconds(), shouldReset("second") ? 0 : date.getMilliseconds());
100 return newDate;
101};
102var ganttDateRange = function ganttDateRange(tasks, viewMode, preStepsCount) {
103 var newStartDate = tasks[0].start;
104 var newEndDate = tasks[0].start;
105
106 for (var _iterator = _createForOfIteratorHelperLoose(tasks), _step; !(_step = _iterator()).done;) {
107 var task = _step.value;
108
109 if (task.start < newStartDate) {
110 newStartDate = task.start;
111 }
112
113 if (task.end > newEndDate) {
114 newEndDate = task.end;
115 }
116 }
117
118 switch (viewMode) {
119 case ViewMode.Year:
120 newStartDate = addToDate(newStartDate, -1, "year");
121 newStartDate = startOfDate(newStartDate, "year");
122 newEndDate = addToDate(newEndDate, 1, "year");
123 newEndDate = startOfDate(newEndDate, "year");
124 break;
125
126 case ViewMode.Month:
127 newStartDate = addToDate(newStartDate, -1 * preStepsCount, "month");
128 newStartDate = startOfDate(newStartDate, "month");
129 newEndDate = addToDate(newEndDate, 1, "year");
130 newEndDate = startOfDate(newEndDate, "year");
131 break;
132
133 case ViewMode.Week:
134 newStartDate = startOfDate(newStartDate, "day");
135 newStartDate = addToDate(getMonday(newStartDate), -7 * preStepsCount, "day");
136 newEndDate = startOfDate(newEndDate, "day");
137 newEndDate = addToDate(newEndDate, 1.5, "month");
138 break;
139
140 case ViewMode.Day:
141 newStartDate = startOfDate(newStartDate, "day");
142 newStartDate = addToDate(newStartDate, -1 * preStepsCount, "day");
143 newEndDate = startOfDate(newEndDate, "day");
144 newEndDate = addToDate(newEndDate, 19, "day");
145 break;
146
147 case ViewMode.QuarterDay:
148 newStartDate = startOfDate(newStartDate, "day");
149 newStartDate = addToDate(newStartDate, -1 * preStepsCount, "day");
150 newEndDate = startOfDate(newEndDate, "day");
151 newEndDate = addToDate(newEndDate, 66, "hour");
152 break;
153
154 case ViewMode.HalfDay:
155 newStartDate = startOfDate(newStartDate, "day");
156 newStartDate = addToDate(newStartDate, -1 * preStepsCount, "day");
157 newEndDate = startOfDate(newEndDate, "day");
158 newEndDate = addToDate(newEndDate, 108, "hour");
159 break;
160
161 case ViewMode.Hour:
162 newStartDate = startOfDate(newStartDate, "hour");
163 newStartDate = addToDate(newStartDate, -1 * preStepsCount, "hour");
164 newEndDate = startOfDate(newEndDate, "day");
165 newEndDate = addToDate(newEndDate, 1, "day");
166 break;
167 }
168
169 return [newStartDate, newEndDate];
170};
171var seedDates = function seedDates(startDate, endDate, viewMode) {
172 var currentDate = new Date(startDate);
173 var dates = [currentDate];
174
175 while (currentDate < endDate) {
176 switch (viewMode) {
177 case ViewMode.Year:
178 currentDate = addToDate(currentDate, 1, "year");
179 break;
180
181 case ViewMode.Month:
182 currentDate = addToDate(currentDate, 1, "month");
183 break;
184
185 case ViewMode.Week:
186 currentDate = addToDate(currentDate, 7, "day");
187 break;
188
189 case ViewMode.Day:
190 currentDate = addToDate(currentDate, 1, "day");
191 break;
192
193 case ViewMode.HalfDay:
194 currentDate = addToDate(currentDate, 12, "hour");
195 break;
196
197 case ViewMode.QuarterDay:
198 currentDate = addToDate(currentDate, 6, "hour");
199 break;
200
201 case ViewMode.Hour:
202 currentDate = addToDate(currentDate, 1, "hour");
203 break;
204 }
205
206 dates.push(currentDate);
207 }
208
209 return dates;
210};
211var getLocaleMonth = function getLocaleMonth(date, locale) {
212 var bottomValue = getCachedDateTimeFormat(locale, {
213 month: "long"
214 }).format(date);
215 bottomValue = bottomValue.replace(bottomValue[0], bottomValue[0].toLocaleUpperCase());
216 return bottomValue;
217};
218var getLocalDayOfWeek = function getLocalDayOfWeek(date, locale, format) {
219 var bottomValue = getCachedDateTimeFormat(locale, {
220 weekday: format
221 }).format(date);
222 bottomValue = bottomValue.replace(bottomValue[0], bottomValue[0].toLocaleUpperCase());
223 return bottomValue;
224};
225
226var getMonday = function getMonday(date) {
227 var day = date.getDay();
228 var diff = date.getDate() - day + (day === 0 ? -6 : 1);
229 return new Date(date.setDate(diff));
230};
231
232var getWeekNumberISO8601 = function getWeekNumberISO8601(date) {
233 var tmpDate = new Date(date.valueOf());
234 var dayNumber = (tmpDate.getDay() + 6) % 7;
235 tmpDate.setDate(tmpDate.getDate() - dayNumber + 3);
236 var firstThursday = tmpDate.valueOf();
237 tmpDate.setMonth(0, 1);
238
239 if (tmpDate.getDay() !== 4) {
240 tmpDate.setMonth(0, 1 + (4 - tmpDate.getDay() + 7) % 7);
241 }
242
243 var weekNumber = (1 + Math.ceil((firstThursday - tmpDate.valueOf()) / 604800000)).toString();
244
245 if (weekNumber.length === 1) {
246 return "0" + weekNumber;
247 } else {
248 return weekNumber;
249 }
250};
251var getDaysInMonth = function getDaysInMonth(month, year) {
252 return new Date(year, month + 1, 0).getDate();
253};
254
255var styles = {"ganttTable":"_3_ygE","ganttTable_Header":"_1nBOt","ganttTable_HeaderSeparator":"_2eZzQ","ganttTable_HeaderItem":"_WuQ0f"};
256
257var TaskListHeaderDefault = function TaskListHeaderDefault(_ref) {
258 var headerHeight = _ref.headerHeight,
259 fontFamily = _ref.fontFamily,
260 fontSize = _ref.fontSize,
261 rowWidth = _ref.rowWidth;
262 return React.createElement("div", {
263 className: styles.ganttTable,
264 style: {
265 fontFamily: fontFamily,
266 fontSize: fontSize
267 }
268 }, React.createElement("div", {
269 className: styles.ganttTable_Header,
270 style: {
271 height: headerHeight - 2
272 }
273 }, React.createElement("div", {
274 className: styles.ganttTable_HeaderItem,
275 style: {
276 minWidth: rowWidth
277 }
278 }, "\xA0Name"), React.createElement("div", {
279 className: styles.ganttTable_HeaderSeparator,
280 style: {
281 height: headerHeight * 0.5,
282 marginTop: headerHeight * 0.2
283 }
284 }), React.createElement("div", {
285 className: styles.ganttTable_HeaderItem,
286 style: {
287 minWidth: rowWidth
288 }
289 }, "\xA0From"), React.createElement("div", {
290 className: styles.ganttTable_HeaderSeparator,
291 style: {
292 height: headerHeight * 0.5,
293 marginTop: headerHeight * 0.25
294 }
295 }), React.createElement("div", {
296 className: styles.ganttTable_HeaderItem,
297 style: {
298 minWidth: rowWidth
299 }
300 }, "\xA0To")));
301};
302
303var styles$1 = {"taskListWrapper":"_3ZbQT","taskListTableRow":"_34SS0","taskListCell":"_3lLk3","taskListNameWrapper":"_nI1Xw","taskListExpander":"_2QjE6","taskListEmptyExpander":"_2TfEi"};
304
305var localeDateStringCache = {};
306
307var toLocaleDateStringFactory = function toLocaleDateStringFactory(locale) {
308 return function (date, dateTimeOptions) {
309 var key = date.toString();
310 var lds = localeDateStringCache[key];
311
312 if (!lds) {
313 lds = date.toLocaleDateString(locale, dateTimeOptions);
314 localeDateStringCache[key] = lds;
315 }
316
317 return lds;
318 };
319};
320
321var dateTimeOptions = {
322 weekday: "short",
323 year: "numeric",
324 month: "long",
325 day: "numeric"
326};
327var TaskListTableDefault = function TaskListTableDefault(_ref) {
328 var rowHeight = _ref.rowHeight,
329 rowWidth = _ref.rowWidth,
330 tasks = _ref.tasks,
331 fontFamily = _ref.fontFamily,
332 fontSize = _ref.fontSize,
333 locale = _ref.locale,
334 onExpanderClick = _ref.onExpanderClick;
335 var toLocaleDateString = useMemo(function () {
336 return toLocaleDateStringFactory(locale);
337 }, [locale]);
338 return React.createElement("div", {
339 className: styles$1.taskListWrapper,
340 style: {
341 fontFamily: fontFamily,
342 fontSize: fontSize
343 }
344 }, tasks.map(function (t) {
345 var expanderSymbol = "";
346
347 if (t.hideChildren === false) {
348 expanderSymbol = "▼";
349 } else if (t.hideChildren === true) {
350 expanderSymbol = "▶";
351 }
352
353 return React.createElement("div", {
354 className: styles$1.taskListTableRow,
355 style: {
356 height: rowHeight
357 },
358 key: t.id + "row"
359 }, React.createElement("div", {
360 className: styles$1.taskListCell,
361 style: {
362 minWidth: rowWidth,
363 maxWidth: rowWidth
364 },
365 title: t.name
366 }, React.createElement("div", {
367 className: styles$1.taskListNameWrapper
368 }, React.createElement("div", {
369 className: expanderSymbol ? styles$1.taskListExpander : styles$1.taskListEmptyExpander,
370 onClick: function onClick() {
371 return onExpanderClick(t);
372 }
373 }, expanderSymbol), React.createElement("div", null, t.name))), React.createElement("div", {
374 className: styles$1.taskListCell,
375 style: {
376 minWidth: rowWidth,
377 maxWidth: rowWidth
378 }
379 }, "\xA0", toLocaleDateString(t.start, dateTimeOptions)), React.createElement("div", {
380 className: styles$1.taskListCell,
381 style: {
382 minWidth: rowWidth,
383 maxWidth: rowWidth
384 }
385 }, "\xA0", toLocaleDateString(t.end, dateTimeOptions)));
386 }));
387};
388
389var styles$2 = {"tooltipDefaultContainer":"_3T42e","tooltipDefaultContainerParagraph":"_29NTg","tooltipDetailsContainer":"_25P-K","tooltipDetailsContainerHidden":"_3gVAq"};
390
391var Tooltip = function Tooltip(_ref) {
392 var task = _ref.task,
393 rowHeight = _ref.rowHeight,
394 rtl = _ref.rtl,
395 svgContainerHeight = _ref.svgContainerHeight,
396 svgContainerWidth = _ref.svgContainerWidth,
397 scrollX = _ref.scrollX,
398 scrollY = _ref.scrollY,
399 arrowIndent = _ref.arrowIndent,
400 fontSize = _ref.fontSize,
401 fontFamily = _ref.fontFamily,
402 headerHeight = _ref.headerHeight,
403 taskListWidth = _ref.taskListWidth,
404 TooltipContent = _ref.TooltipContent;
405 var tooltipRef = useRef(null);
406
407 var _useState = useState(0),
408 relatedY = _useState[0],
409 setRelatedY = _useState[1];
410
411 var _useState2 = useState(0),
412 relatedX = _useState2[0],
413 setRelatedX = _useState2[1];
414
415 useEffect(function () {
416 if (tooltipRef.current) {
417 var tooltipHeight = tooltipRef.current.offsetHeight * 1.1;
418 var tooltipWidth = tooltipRef.current.offsetWidth * 1.1;
419 var newRelatedY = task.index * rowHeight - scrollY + headerHeight;
420 var newRelatedX;
421
422 if (rtl) {
423 newRelatedX = task.x1 - arrowIndent * 1.5 - tooltipWidth - scrollX;
424
425 if (newRelatedX < 0) {
426 newRelatedX = task.x2 + arrowIndent * 1.5 - scrollX;
427 }
428
429 var tooltipLeftmostPoint = tooltipWidth + newRelatedX;
430
431 if (tooltipLeftmostPoint > svgContainerWidth) {
432 newRelatedX = svgContainerWidth - tooltipWidth;
433 newRelatedY += rowHeight;
434 }
435 } else {
436 newRelatedX = task.x2 + arrowIndent * 1.5 + taskListWidth - scrollX;
437
438 var _tooltipLeftmostPoint = tooltipWidth + newRelatedX;
439
440 var fullChartWidth = taskListWidth + svgContainerWidth;
441
442 if (_tooltipLeftmostPoint > fullChartWidth) {
443 newRelatedX = task.x1 + taskListWidth - arrowIndent * 1.5 - scrollX - tooltipWidth;
444 }
445
446 if (newRelatedX < taskListWidth) {
447 newRelatedX = svgContainerWidth + taskListWidth - tooltipWidth;
448 newRelatedY += rowHeight;
449 }
450 }
451
452 var tooltipLowerPoint = tooltipHeight + newRelatedY - scrollY;
453
454 if (tooltipLowerPoint > svgContainerHeight - scrollY) {
455 newRelatedY = svgContainerHeight - tooltipHeight;
456 }
457
458 setRelatedY(newRelatedY);
459 setRelatedX(newRelatedX);
460 }
461 }, [tooltipRef, task, arrowIndent, scrollX, scrollY, headerHeight, taskListWidth, rowHeight, svgContainerHeight, svgContainerWidth, rtl]);
462 return React.createElement("div", {
463 ref: tooltipRef,
464 className: relatedX ? styles$2.tooltipDetailsContainer : styles$2.tooltipDetailsContainerHidden,
465 style: {
466 left: relatedX,
467 top: relatedY
468 }
469 }, React.createElement(TooltipContent, {
470 task: task,
471 fontSize: fontSize,
472 fontFamily: fontFamily
473 }));
474};
475var StandardTooltipContent = function StandardTooltipContent(_ref2) {
476 var task = _ref2.task,
477 fontSize = _ref2.fontSize,
478 fontFamily = _ref2.fontFamily;
479 var style = {
480 fontSize: fontSize,
481 fontFamily: fontFamily
482 };
483 return React.createElement("div", {
484 className: styles$2.tooltipDefaultContainer,
485 style: style
486 }, React.createElement("b", {
487 style: {
488 fontSize: fontSize + 6
489 }
490 }, task.name + ": " + task.start.getDate() + "-" + (task.start.getMonth() + 1) + "-" + task.start.getFullYear() + " - " + task.end.getDate() + "-" + (task.end.getMonth() + 1) + "-" + task.end.getFullYear()), task.end.getTime() - task.start.getTime() !== 0 && React.createElement("p", {
491 className: styles$2.tooltipDefaultContainerParagraph
492 }, "Duration: " + ~~((task.end.getTime() - task.start.getTime()) / (1000 * 60 * 60 * 24)) + " day(s)"), React.createElement("p", {
493 className: styles$2.tooltipDefaultContainerParagraph
494 }, !!task.progress && "Progress: " + task.progress + " %"));
495};
496
497var styles$3 = {"scroll":"_1eT-t"};
498
499var VerticalScroll = function VerticalScroll(_ref) {
500 var scroll = _ref.scroll,
501 ganttHeight = _ref.ganttHeight,
502 ganttFullHeight = _ref.ganttFullHeight,
503 headerHeight = _ref.headerHeight,
504 rtl = _ref.rtl,
505 onScroll = _ref.onScroll;
506 var scrollRef = useRef(null);
507 useEffect(function () {
508 if (scrollRef.current) {
509 scrollRef.current.scrollTop = scroll;
510 }
511 }, [scroll]);
512 return React.createElement("div", {
513 style: {
514 height: ganttHeight,
515 marginTop: headerHeight,
516 marginLeft: rtl ? "" : "-1rem"
517 },
518 className: styles$3.scroll,
519 onScroll: onScroll,
520 ref: scrollRef
521 }, React.createElement("div", {
522 style: {
523 height: ganttFullHeight,
524 width: 1
525 }
526 }));
527};
528
529var TaskList = function TaskList(_ref) {
530 var headerHeight = _ref.headerHeight,
531 fontFamily = _ref.fontFamily,
532 fontSize = _ref.fontSize,
533 rowWidth = _ref.rowWidth,
534 rowHeight = _ref.rowHeight,
535 scrollY = _ref.scrollY,
536 tasks = _ref.tasks,
537 selectedTask = _ref.selectedTask,
538 setSelectedTask = _ref.setSelectedTask,
539 onExpanderClick = _ref.onExpanderClick,
540 locale = _ref.locale,
541 ganttHeight = _ref.ganttHeight,
542 taskListRef = _ref.taskListRef,
543 horizontalContainerClass = _ref.horizontalContainerClass,
544 TaskListHeader = _ref.TaskListHeader,
545 TaskListTable = _ref.TaskListTable;
546 var horizontalContainerRef = useRef(null);
547 useEffect(function () {
548 if (horizontalContainerRef.current) {
549 horizontalContainerRef.current.scrollTop = scrollY;
550 }
551 }, [scrollY]);
552 var headerProps = {
553 headerHeight: headerHeight,
554 fontFamily: fontFamily,
555 fontSize: fontSize,
556 rowWidth: rowWidth
557 };
558 var selectedTaskId = selectedTask ? selectedTask.id : "";
559 var tableProps = {
560 rowHeight: rowHeight,
561 rowWidth: rowWidth,
562 fontFamily: fontFamily,
563 fontSize: fontSize,
564 tasks: tasks,
565 locale: locale,
566 selectedTaskId: selectedTaskId,
567 setSelectedTask: setSelectedTask,
568 onExpanderClick: onExpanderClick
569 };
570 return React.createElement("div", {
571 ref: taskListRef
572 }, React.createElement(TaskListHeader, Object.assign({}, headerProps)), React.createElement("div", {
573 ref: horizontalContainerRef,
574 className: horizontalContainerClass,
575 style: ganttHeight ? {
576 height: ganttHeight
577 } : {}
578 }, React.createElement(TaskListTable, Object.assign({}, tableProps))));
579};
580
581var styles$4 = {"gridRow":"_2dZTy","gridRowLine":"_3rUKi","gridTick":"_RuwuK"};
582
583var GridBody = function GridBody(_ref) {
584 var tasks = _ref.tasks,
585 dates = _ref.dates,
586 rowHeight = _ref.rowHeight,
587 svgWidth = _ref.svgWidth,
588 columnWidth = _ref.columnWidth,
589 todayColor = _ref.todayColor,
590 rtl = _ref.rtl;
591 var y = 0;
592 var gridRows = [];
593 var rowLines = [React.createElement("line", {
594 key: "RowLineFirst",
595 x: "0",
596 y1: 0,
597 x2: svgWidth,
598 y2: 0,
599 className: styles$4.gridRowLine
600 })];
601
602 for (var _iterator = _createForOfIteratorHelperLoose(tasks), _step; !(_step = _iterator()).done;) {
603 var task = _step.value;
604 gridRows.push(React.createElement("rect", {
605 key: "Row" + task.id,
606 x: "0",
607 y: y,
608 width: svgWidth,
609 height: rowHeight,
610 className: styles$4.gridRow
611 }));
612 rowLines.push(React.createElement("line", {
613 key: "RowLine" + task.id,
614 x: "0",
615 y1: y + rowHeight,
616 x2: svgWidth,
617 y2: y + rowHeight,
618 className: styles$4.gridRowLine
619 }));
620 y += rowHeight;
621 }
622
623 var now = new Date();
624 var tickX = 0;
625 var ticks = [];
626 var today = React.createElement("rect", null);
627
628 for (var i = 0; i < dates.length; i++) {
629 var date = dates[i];
630 ticks.push(React.createElement("line", {
631 key: date.getTime(),
632 x1: tickX,
633 y1: 0,
634 x2: tickX,
635 y2: y,
636 className: styles$4.gridTick
637 }));
638
639 if (i + 1 !== dates.length && date.getTime() < now.getTime() && dates[i + 1].getTime() >= now.getTime() || i !== 0 && i + 1 === dates.length && date.getTime() < now.getTime() && addToDate(date, date.getTime() - dates[i - 1].getTime(), "millisecond").getTime() >= now.getTime()) {
640 today = React.createElement("rect", {
641 x: tickX,
642 y: 0,
643 width: columnWidth,
644 height: y,
645 fill: todayColor
646 });
647 }
648
649 if (rtl && i + 1 !== dates.length && date.getTime() >= now.getTime() && dates[i + 1].getTime() < now.getTime()) {
650 today = React.createElement("rect", {
651 x: tickX + columnWidth,
652 y: 0,
653 width: columnWidth,
654 height: y,
655 fill: todayColor
656 });
657 }
658
659 tickX += columnWidth;
660 }
661
662 return React.createElement("g", {
663 className: "gridBody"
664 }, React.createElement("g", {
665 className: "rows"
666 }, gridRows), React.createElement("g", {
667 className: "rowLines"
668 }, rowLines), React.createElement("g", {
669 className: "ticks"
670 }, ticks), React.createElement("g", {
671 className: "today"
672 }, today));
673};
674
675var Grid = function Grid(props) {
676 return React.createElement("g", {
677 className: "grid"
678 }, React.createElement(GridBody, Object.assign({}, props)));
679};
680
681var styles$5 = {"calendarBottomText":"_9w8d5","calendarTopTick":"_1rLuZ","calendarTopText":"_2q1Kt","calendarHeader":"_35nLX"};
682
683var TopPartOfCalendar = function TopPartOfCalendar(_ref) {
684 var value = _ref.value,
685 x1Line = _ref.x1Line,
686 y1Line = _ref.y1Line,
687 y2Line = _ref.y2Line,
688 xText = _ref.xText,
689 yText = _ref.yText;
690 return React.createElement("g", {
691 className: "calendarTop"
692 }, React.createElement("line", {
693 x1: x1Line,
694 y1: y1Line,
695 x2: x1Line,
696 y2: y2Line,
697 className: styles$5.calendarTopTick,
698 key: value + "line"
699 }), React.createElement("text", {
700 key: value + "text",
701 y: yText,
702 x: xText,
703 className: styles$5.calendarTopText
704 }, value));
705};
706
707var Calendar = function Calendar(_ref) {
708 var dateSetup = _ref.dateSetup,
709 locale = _ref.locale,
710 viewMode = _ref.viewMode,
711 rtl = _ref.rtl,
712 headerHeight = _ref.headerHeight,
713 columnWidth = _ref.columnWidth,
714 fontFamily = _ref.fontFamily,
715 fontSize = _ref.fontSize;
716
717 var getCalendarValuesForYear = function getCalendarValuesForYear() {
718 var topValues = [];
719 var bottomValues = [];
720 var topDefaultHeight = headerHeight * 0.5;
721
722 for (var i = 0; i < dateSetup.dates.length; i++) {
723 var date = dateSetup.dates[i];
724 var bottomValue = date.getFullYear();
725 bottomValues.push(React.createElement("text", {
726 key: date.getFullYear(),
727 y: headerHeight * 0.8,
728 x: columnWidth * i + columnWidth * 0.5,
729 className: styles$5.calendarBottomText
730 }, bottomValue));
731
732 if (i === 0 || date.getFullYear() !== dateSetup.dates[i - 1].getFullYear()) {
733 var topValue = date.getFullYear().toString();
734 var xText = void 0;
735
736 if (rtl) {
737 xText = (6 + i + date.getFullYear() + 1) * columnWidth;
738 } else {
739 xText = (6 + i - date.getFullYear()) * columnWidth;
740 }
741
742 topValues.push(React.createElement(TopPartOfCalendar, {
743 key: topValue,
744 value: topValue,
745 x1Line: columnWidth * i,
746 y1Line: 0,
747 y2Line: headerHeight,
748 xText: xText,
749 yText: topDefaultHeight * 0.9
750 }));
751 }
752 }
753
754 return [topValues, bottomValues];
755 };
756
757 var getCalendarValuesForMonth = function getCalendarValuesForMonth() {
758 var topValues = [];
759 var bottomValues = [];
760 var topDefaultHeight = headerHeight * 0.5;
761
762 for (var i = 0; i < dateSetup.dates.length; i++) {
763 var date = dateSetup.dates[i];
764 var bottomValue = getLocaleMonth(date, locale);
765 bottomValues.push(React.createElement("text", {
766 key: bottomValue + date.getFullYear(),
767 y: headerHeight * 0.8,
768 x: columnWidth * i + columnWidth * 0.5,
769 className: styles$5.calendarBottomText
770 }, bottomValue));
771
772 if (i === 0 || date.getFullYear() !== dateSetup.dates[i - 1].getFullYear()) {
773 var topValue = date.getFullYear().toString();
774 var xText = void 0;
775
776 if (rtl) {
777 xText = (6 + i + date.getMonth() + 1) * columnWidth;
778 } else {
779 xText = (6 + i - date.getMonth()) * columnWidth;
780 }
781
782 topValues.push(React.createElement(TopPartOfCalendar, {
783 key: topValue,
784 value: topValue,
785 x1Line: columnWidth * i,
786 y1Line: 0,
787 y2Line: topDefaultHeight,
788 xText: xText,
789 yText: topDefaultHeight * 0.9
790 }));
791 }
792 }
793
794 return [topValues, bottomValues];
795 };
796
797 var getCalendarValuesForWeek = function getCalendarValuesForWeek() {
798 var topValues = [];
799 var bottomValues = [];
800 var weeksCount = 1;
801 var topDefaultHeight = headerHeight * 0.5;
802 var dates = dateSetup.dates;
803
804 for (var i = dates.length - 1; i >= 0; i--) {
805 var date = dates[i];
806 var topValue = "";
807
808 if (i === 0 || date.getMonth() !== dates[i - 1].getMonth()) {
809 topValue = getLocaleMonth(date, locale) + ", " + date.getFullYear();
810 }
811
812 var bottomValue = "W" + getWeekNumberISO8601(date);
813 bottomValues.push(React.createElement("text", {
814 key: date.getTime(),
815 y: headerHeight * 0.8,
816 x: columnWidth * (i + +rtl),
817 className: styles$5.calendarBottomText
818 }, bottomValue));
819
820 if (topValue) {
821 if (i !== dates.length - 1) {
822 topValues.push(React.createElement(TopPartOfCalendar, {
823 key: topValue,
824 value: topValue,
825 x1Line: columnWidth * i + weeksCount * columnWidth,
826 y1Line: 0,
827 y2Line: topDefaultHeight,
828 xText: columnWidth * i + columnWidth * weeksCount * 0.5,
829 yText: topDefaultHeight * 0.9
830 }));
831 }
832
833 weeksCount = 0;
834 }
835
836 weeksCount++;
837 }
838
839 return [topValues, bottomValues];
840 };
841
842 var getCalendarValuesForDay = function getCalendarValuesForDay() {
843 var topValues = [];
844 var bottomValues = [];
845 var topDefaultHeight = headerHeight * 0.5;
846 var dates = dateSetup.dates;
847
848 for (var i = 0; i < dates.length; i++) {
849 var date = dates[i];
850 var bottomValue = getLocalDayOfWeek(date, locale, "short") + ", " + date.getDate().toString();
851 bottomValues.push(React.createElement("text", {
852 key: date.getTime(),
853 y: headerHeight * 0.8,
854 x: columnWidth * i + columnWidth * 0.5,
855 className: styles$5.calendarBottomText
856 }, bottomValue));
857
858 if (i + 1 !== dates.length && date.getMonth() !== dates[i + 1].getMonth()) {
859 var topValue = getLocaleMonth(date, locale);
860 topValues.push(React.createElement(TopPartOfCalendar, {
861 key: topValue + date.getFullYear(),
862 value: topValue,
863 x1Line: columnWidth * (i + 1),
864 y1Line: 0,
865 y2Line: topDefaultHeight,
866 xText: columnWidth * (i + 1) - getDaysInMonth(date.getMonth(), date.getFullYear()) * columnWidth * 0.5,
867 yText: topDefaultHeight * 0.9
868 }));
869 }
870 }
871
872 return [topValues, bottomValues];
873 };
874
875 var getCalendarValuesForPartOfDay = function getCalendarValuesForPartOfDay() {
876 var topValues = [];
877 var bottomValues = [];
878 var ticks = viewMode === ViewMode.HalfDay ? 2 : 4;
879 var topDefaultHeight = headerHeight * 0.5;
880 var dates = dateSetup.dates;
881
882 for (var i = 0; i < dates.length; i++) {
883 var date = dates[i];
884 var bottomValue = getCachedDateTimeFormat(locale, {
885 hour: "numeric"
886 }).format(date);
887 bottomValues.push(React.createElement("text", {
888 key: date.getTime(),
889 y: headerHeight * 0.8,
890 x: columnWidth * (i + +rtl),
891 className: styles$5.calendarBottomText,
892 fontFamily: fontFamily
893 }, bottomValue));
894
895 if (i === 0 || date.getDate() !== dates[i - 1].getDate()) {
896 var topValue = getLocalDayOfWeek(date, locale, "short") + ", " + date.getDate() + " " + getLocaleMonth(date, locale);
897 topValues.push(React.createElement(TopPartOfCalendar, {
898 key: topValue + date.getFullYear(),
899 value: topValue,
900 x1Line: columnWidth * i + ticks * columnWidth,
901 y1Line: 0,
902 y2Line: topDefaultHeight,
903 xText: columnWidth * i + ticks * columnWidth * 0.5,
904 yText: topDefaultHeight * 0.9
905 }));
906 }
907 }
908
909 return [topValues, bottomValues];
910 };
911
912 var getCalendarValuesForHour = function getCalendarValuesForHour() {
913 var topValues = [];
914 var bottomValues = [];
915 var topDefaultHeight = headerHeight * 0.5;
916 var dates = dateSetup.dates;
917
918 for (var i = 0; i < dates.length; i++) {
919 var date = dates[i];
920 var bottomValue = getCachedDateTimeFormat(locale, {
921 hour: "numeric"
922 }).format(date);
923 bottomValues.push(React.createElement("text", {
924 key: date.getTime(),
925 y: headerHeight * 0.8,
926 x: columnWidth * (i + +rtl),
927 className: styles$5.calendarBottomText,
928 fontFamily: fontFamily
929 }, bottomValue));
930
931 if (i !== 0 && date.getDate() !== dates[i - 1].getDate()) {
932 var displayDate = dates[i - 1];
933 var topValue = getLocalDayOfWeek(displayDate, locale, "long") + ", " + displayDate.getDate() + " " + getLocaleMonth(displayDate, locale);
934 var topPosition = (date.getHours() - 24) / 2;
935 topValues.push(React.createElement(TopPartOfCalendar, {
936 key: topValue + displayDate.getFullYear(),
937 value: topValue,
938 x1Line: columnWidth * i,
939 y1Line: 0,
940 y2Line: topDefaultHeight,
941 xText: columnWidth * (i + topPosition),
942 yText: topDefaultHeight * 0.9
943 }));
944 }
945 }
946
947 return [topValues, bottomValues];
948 };
949
950 var topValues = [];
951 var bottomValues = [];
952
953 switch (dateSetup.viewMode) {
954 case ViewMode.Year:
955 var _getCalendarValuesFor = getCalendarValuesForYear();
956
957 topValues = _getCalendarValuesFor[0];
958 bottomValues = _getCalendarValuesFor[1];
959 break;
960
961 case ViewMode.Month:
962 var _getCalendarValuesFor2 = getCalendarValuesForMonth();
963
964 topValues = _getCalendarValuesFor2[0];
965 bottomValues = _getCalendarValuesFor2[1];
966 break;
967
968 case ViewMode.Week:
969 var _getCalendarValuesFor3 = getCalendarValuesForWeek();
970
971 topValues = _getCalendarValuesFor3[0];
972 bottomValues = _getCalendarValuesFor3[1];
973 break;
974
975 case ViewMode.Day:
976 var _getCalendarValuesFor4 = getCalendarValuesForDay();
977
978 topValues = _getCalendarValuesFor4[0];
979 bottomValues = _getCalendarValuesFor4[1];
980 break;
981
982 case ViewMode.QuarterDay:
983 case ViewMode.HalfDay:
984 var _getCalendarValuesFor5 = getCalendarValuesForPartOfDay();
985
986 topValues = _getCalendarValuesFor5[0];
987 bottomValues = _getCalendarValuesFor5[1];
988 break;
989
990 case ViewMode.Hour:
991 var _getCalendarValuesFor6 = getCalendarValuesForHour();
992
993 topValues = _getCalendarValuesFor6[0];
994 bottomValues = _getCalendarValuesFor6[1];
995 }
996
997 return React.createElement("g", {
998 className: "calendar",
999 fontSize: fontSize,
1000 fontFamily: fontFamily
1001 }, React.createElement("rect", {
1002 x: 0,
1003 y: 0,
1004 width: columnWidth * dateSetup.dates.length,
1005 height: headerHeight,
1006 className: styles$5.calendarHeader
1007 }), bottomValues, " ", topValues);
1008};
1009
1010// A type of promise-like that resolves synchronously and supports only one observer
1011
1012const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
1013
1014const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
1015
1016// Asynchronously call a function and send errors to recovery continuation
1017function _catch(body, recover) {
1018 try {
1019 var result = body();
1020 } catch(e) {
1021 return recover(e);
1022 }
1023 if (result && result.then) {
1024 return result.then(void 0, recover);
1025 }
1026 return result;
1027}
1028
1029var Arrow = function Arrow(_ref) {
1030 var taskFrom = _ref.taskFrom,
1031 taskTo = _ref.taskTo,
1032 rowHeight = _ref.rowHeight,
1033 taskHeight = _ref.taskHeight,
1034 arrowIndent = _ref.arrowIndent,
1035 rtl = _ref.rtl;
1036 var path;
1037 var trianglePoints;
1038
1039 if (rtl) {
1040 var _drownPathAndTriangle = drownPathAndTriangleRTL(taskFrom, taskTo, rowHeight, taskHeight, arrowIndent);
1041
1042 path = _drownPathAndTriangle[0];
1043 trianglePoints = _drownPathAndTriangle[1];
1044 } else {
1045 var _drownPathAndTriangle2 = drownPathAndTriangle(taskFrom, taskTo, rowHeight, taskHeight, arrowIndent);
1046
1047 path = _drownPathAndTriangle2[0];
1048 trianglePoints = _drownPathAndTriangle2[1];
1049 }
1050
1051 return React.createElement("g", {
1052 className: "arrow"
1053 }, React.createElement("path", {
1054 strokeWidth: "1.5",
1055 d: path,
1056 fill: "none"
1057 }), React.createElement("polygon", {
1058 points: trianglePoints
1059 }));
1060};
1061
1062var drownPathAndTriangle = function drownPathAndTriangle(taskFrom, taskTo, rowHeight, taskHeight, arrowIndent) {
1063 var indexCompare = taskFrom.index > taskTo.index ? -1 : 1;
1064 var taskToEndPosition = taskTo.y + taskHeight / 2;
1065 var taskFromEndPosition = taskFrom.x2 + arrowIndent * 2;
1066 var taskFromHorizontalOffsetValue = taskFromEndPosition < taskTo.x1 ? "" : "H " + (taskTo.x1 - arrowIndent);
1067 var taskToHorizontalOffsetValue = taskFromEndPosition > taskTo.x1 ? arrowIndent : taskTo.x1 - taskFrom.x2 - arrowIndent;
1068 var path = "M " + taskFrom.x2 + " " + (taskFrom.y + taskHeight / 2) + " \n h " + arrowIndent + " \n v " + indexCompare * rowHeight / 2 + " \n " + taskFromHorizontalOffsetValue + "\n V " + taskToEndPosition + " \n h " + taskToHorizontalOffsetValue;
1069 var trianglePoints = taskTo.x1 + "," + taskToEndPosition + " \n " + (taskTo.x1 - 5) + "," + (taskToEndPosition - 5) + " \n " + (taskTo.x1 - 5) + "," + (taskToEndPosition + 5);
1070 return [path, trianglePoints];
1071};
1072
1073var drownPathAndTriangleRTL = function drownPathAndTriangleRTL(taskFrom, taskTo, rowHeight, taskHeight, arrowIndent) {
1074 var indexCompare = taskFrom.index > taskTo.index ? -1 : 1;
1075 var taskToEndPosition = taskTo.y + taskHeight / 2;
1076 var taskFromEndPosition = taskFrom.x1 - arrowIndent * 2;
1077 var taskFromHorizontalOffsetValue = taskFromEndPosition > taskTo.x2 ? "" : "H " + (taskTo.x2 + arrowIndent);
1078 var taskToHorizontalOffsetValue = taskFromEndPosition < taskTo.x2 ? -arrowIndent : taskTo.x2 - taskFrom.x1 + arrowIndent;
1079 var path = "M " + taskFrom.x1 + " " + (taskFrom.y + taskHeight / 2) + " \n h " + -arrowIndent + " \n v " + indexCompare * rowHeight / 2 + " \n " + taskFromHorizontalOffsetValue + "\n V " + taskToEndPosition + " \n h " + taskToHorizontalOffsetValue;
1080 var trianglePoints = taskTo.x2 + "," + taskToEndPosition + " \n " + (taskTo.x2 + 5) + "," + (taskToEndPosition + 5) + " \n " + (taskTo.x2 + 5) + "," + (taskToEndPosition - 5);
1081 return [path, trianglePoints];
1082};
1083
1084var convertToBarTasks = function convertToBarTasks(tasks, dates, columnWidth, rowHeight, taskHeight, barCornerRadius, handleWidth, rtl, barProgressColor, barProgressSelectedColor, barBackgroundColor, barBackgroundSelectedColor, projectProgressColor, projectProgressSelectedColor, projectBackgroundColor, projectBackgroundSelectedColor, milestoneBackgroundColor, milestoneBackgroundSelectedColor) {
1085 var barTasks = tasks.map(function (t, i) {
1086 return convertToBarTask(t, i, dates, columnWidth, rowHeight, taskHeight, barCornerRadius, handleWidth, rtl, barProgressColor, barProgressSelectedColor, barBackgroundColor, barBackgroundSelectedColor, projectProgressColor, projectProgressSelectedColor, projectBackgroundColor, projectBackgroundSelectedColor, milestoneBackgroundColor, milestoneBackgroundSelectedColor);
1087 });
1088 barTasks = barTasks.map(function (task) {
1089 var dependencies = task.dependencies || [];
1090
1091 var _loop = function _loop(j) {
1092 var dependence = barTasks.findIndex(function (value) {
1093 return value.id === dependencies[j];
1094 });
1095 if (dependence !== -1) barTasks[dependence].barChildren.push(task);
1096 };
1097
1098 for (var j = 0; j < dependencies.length; j++) {
1099 _loop(j);
1100 }
1101
1102 return task;
1103 });
1104 return barTasks;
1105};
1106
1107var convertToBarTask = function convertToBarTask(task, index, dates, columnWidth, rowHeight, taskHeight, barCornerRadius, handleWidth, rtl, barProgressColor, barProgressSelectedColor, barBackgroundColor, barBackgroundSelectedColor, projectProgressColor, projectProgressSelectedColor, projectBackgroundColor, projectBackgroundSelectedColor, milestoneBackgroundColor, milestoneBackgroundSelectedColor) {
1108 var barTask;
1109
1110 switch (task.type) {
1111 case "milestone":
1112 barTask = convertToMilestone(task, index, dates, columnWidth, rowHeight, taskHeight, barCornerRadius, handleWidth, milestoneBackgroundColor, milestoneBackgroundSelectedColor);
1113 break;
1114
1115 case "project":
1116 barTask = convertToBar(task, index, dates, columnWidth, rowHeight, taskHeight, barCornerRadius, handleWidth, rtl, projectProgressColor, projectProgressSelectedColor, projectBackgroundColor, projectBackgroundSelectedColor);
1117 break;
1118
1119 default:
1120 barTask = convertToBar(task, index, dates, columnWidth, rowHeight, taskHeight, barCornerRadius, handleWidth, rtl, barProgressColor, barProgressSelectedColor, barBackgroundColor, barBackgroundSelectedColor);
1121 break;
1122 }
1123
1124 return barTask;
1125};
1126
1127var convertToBar = function convertToBar(task, index, dates, columnWidth, rowHeight, taskHeight, barCornerRadius, handleWidth, rtl, barProgressColor, barProgressSelectedColor, barBackgroundColor, barBackgroundSelectedColor) {
1128 var x1;
1129 var x2;
1130
1131 if (rtl) {
1132 x2 = taskXCoordinateRTL(task.start, dates, columnWidth);
1133 x1 = taskXCoordinateRTL(task.end, dates, columnWidth);
1134 } else {
1135 x1 = taskXCoordinate(task.start, dates, columnWidth);
1136 x2 = taskXCoordinate(task.end, dates, columnWidth);
1137 }
1138
1139 var typeInternal = task.type;
1140
1141 if (typeInternal === "task" && x2 - x1 < handleWidth * 2) {
1142 typeInternal = "smalltask";
1143 x2 = x1 + handleWidth * 2;
1144 }
1145
1146 var _progressWithByParams = progressWithByParams(x1, x2, task.progress, rtl),
1147 progressWidth = _progressWithByParams[0],
1148 progressX = _progressWithByParams[1];
1149
1150 var y = taskYCoordinate(index, rowHeight, taskHeight);
1151 var hideChildren = task.type === "project" ? task.hideChildren : undefined;
1152
1153 var styles = _extends({
1154 backgroundColor: barBackgroundColor,
1155 backgroundSelectedColor: barBackgroundSelectedColor,
1156 progressColor: barProgressColor,
1157 progressSelectedColor: barProgressSelectedColor
1158 }, task.styles);
1159
1160 return _extends({}, task, {
1161 typeInternal: typeInternal,
1162 x1: x1,
1163 x2: x2,
1164 y: y,
1165 index: index,
1166 progressX: progressX,
1167 progressWidth: progressWidth,
1168 barCornerRadius: barCornerRadius,
1169 handleWidth: handleWidth,
1170 hideChildren: hideChildren,
1171 height: taskHeight,
1172 barChildren: [],
1173 styles: styles
1174 });
1175};
1176
1177var convertToMilestone = function convertToMilestone(task, index, dates, columnWidth, rowHeight, taskHeight, barCornerRadius, handleWidth, milestoneBackgroundColor, milestoneBackgroundSelectedColor) {
1178 var x = taskXCoordinate(task.start, dates, columnWidth);
1179 var y = taskYCoordinate(index, rowHeight, taskHeight);
1180 var x1 = x - taskHeight * 0.5;
1181 var x2 = x + taskHeight * 0.5;
1182 var rotatedHeight = taskHeight / 1.414;
1183
1184 var styles = _extends({
1185 backgroundColor: milestoneBackgroundColor,
1186 backgroundSelectedColor: milestoneBackgroundSelectedColor,
1187 progressColor: "",
1188 progressSelectedColor: ""
1189 }, task.styles);
1190
1191 return _extends({}, task, {
1192 end: task.start,
1193 x1: x1,
1194 x2: x2,
1195 y: y,
1196 index: index,
1197 progressX: 0,
1198 progressWidth: 0,
1199 barCornerRadius: barCornerRadius,
1200 handleWidth: handleWidth,
1201 typeInternal: task.type,
1202 progress: 0,
1203 height: rotatedHeight,
1204 hideChildren: undefined,
1205 barChildren: [],
1206 styles: styles
1207 });
1208};
1209
1210var taskXCoordinate = function taskXCoordinate(xDate, dates, columnWidth) {
1211 var index = dates.findIndex(function (d) {
1212 return d.getTime() >= xDate.getTime();
1213 }) - 1;
1214 var remainderMillis = xDate.getTime() - dates[index].getTime();
1215 var percentOfInterval = remainderMillis / (dates[index + 1].getTime() - dates[index].getTime());
1216 var x = index * columnWidth + percentOfInterval * columnWidth;
1217 return x;
1218};
1219
1220var taskXCoordinateRTL = function taskXCoordinateRTL(xDate, dates, columnWidth) {
1221 var x = taskXCoordinate(xDate, dates, columnWidth);
1222 x += columnWidth;
1223 return x;
1224};
1225
1226var taskYCoordinate = function taskYCoordinate(index, rowHeight, taskHeight) {
1227 var y = index * rowHeight + (rowHeight - taskHeight) / 2;
1228 return y;
1229};
1230
1231var progressWithByParams = function progressWithByParams(taskX1, taskX2, progress, rtl) {
1232 var progressWidth = (taskX2 - taskX1) * progress * 0.01;
1233 var progressX;
1234
1235 if (rtl) {
1236 progressX = taskX2 - progressWidth;
1237 } else {
1238 progressX = taskX1;
1239 }
1240
1241 return [progressWidth, progressX];
1242};
1243
1244var progressByX = function progressByX(x, task) {
1245 if (x >= task.x2) return 100;else if (x <= task.x1) return 0;else {
1246 var barWidth = task.x2 - task.x1;
1247 var progressPercent = Math.round((x - task.x1) * 100 / barWidth);
1248 return progressPercent;
1249 }
1250};
1251
1252var progressByXRTL = function progressByXRTL(x, task) {
1253 if (x >= task.x2) return 0;else if (x <= task.x1) return 100;else {
1254 var barWidth = task.x2 - task.x1;
1255 var progressPercent = Math.round((task.x2 - x) * 100 / barWidth);
1256 return progressPercent;
1257 }
1258};
1259
1260var getProgressPoint = function getProgressPoint(progressX, taskY, taskHeight) {
1261 var point = [progressX - 5, taskY + taskHeight, progressX + 5, taskY + taskHeight, progressX, taskY + taskHeight - 8.66];
1262 return point.join(",");
1263};
1264
1265var startByX = function startByX(x, xStep, task) {
1266 if (x >= task.x2 - task.handleWidth * 2) {
1267 x = task.x2 - task.handleWidth * 2;
1268 }
1269
1270 var steps = Math.round((x - task.x1) / xStep);
1271 var additionalXValue = steps * xStep;
1272 var newX = task.x1 + additionalXValue;
1273 return newX;
1274};
1275
1276var endByX = function endByX(x, xStep, task) {
1277 if (x <= task.x1 + task.handleWidth * 2) {
1278 x = task.x1 + task.handleWidth * 2;
1279 }
1280
1281 var steps = Math.round((x - task.x2) / xStep);
1282 var additionalXValue = steps * xStep;
1283 var newX = task.x2 + additionalXValue;
1284 return newX;
1285};
1286
1287var moveByX = function moveByX(x, xStep, task) {
1288 var steps = Math.round((x - task.x1) / xStep);
1289 var additionalXValue = steps * xStep;
1290 var newX1 = task.x1 + additionalXValue;
1291 var newX2 = newX1 + task.x2 - task.x1;
1292 return [newX1, newX2];
1293};
1294
1295var dateByX = function dateByX(x, taskX, taskDate, xStep, timeStep) {
1296 var newDate = new Date((x - taskX) / xStep * timeStep + taskDate.getTime());
1297 newDate = new Date(newDate.getTime() + (newDate.getTimezoneOffset() - taskDate.getTimezoneOffset()) * 60000);
1298 return newDate;
1299};
1300
1301var handleTaskBySVGMouseEvent = function handleTaskBySVGMouseEvent(svgX, action, selectedTask, xStep, timeStep, initEventX1Delta, rtl) {
1302 var result;
1303
1304 switch (selectedTask.type) {
1305 case "milestone":
1306 result = handleTaskBySVGMouseEventForMilestone(svgX, action, selectedTask, xStep, timeStep, initEventX1Delta);
1307 break;
1308
1309 default:
1310 result = handleTaskBySVGMouseEventForBar(svgX, action, selectedTask, xStep, timeStep, initEventX1Delta, rtl);
1311 break;
1312 }
1313
1314 return result;
1315};
1316
1317var handleTaskBySVGMouseEventForBar = function handleTaskBySVGMouseEventForBar(svgX, action, selectedTask, xStep, timeStep, initEventX1Delta, rtl) {
1318 var changedTask = _extends({}, selectedTask);
1319
1320 var isChanged = false;
1321
1322 switch (action) {
1323 case "progress":
1324 if (rtl) {
1325 changedTask.progress = progressByXRTL(svgX, selectedTask);
1326 } else {
1327 changedTask.progress = progressByX(svgX, selectedTask);
1328 }
1329
1330 isChanged = changedTask.progress !== selectedTask.progress;
1331
1332 if (isChanged) {
1333 var _progressWithByParams2 = progressWithByParams(changedTask.x1, changedTask.x2, changedTask.progress, rtl),
1334 progressWidth = _progressWithByParams2[0],
1335 progressX = _progressWithByParams2[1];
1336
1337 changedTask.progressWidth = progressWidth;
1338 changedTask.progressX = progressX;
1339 }
1340
1341 break;
1342
1343 case "start":
1344 {
1345 var newX1 = startByX(svgX, xStep, selectedTask);
1346 changedTask.x1 = newX1;
1347 isChanged = changedTask.x1 !== selectedTask.x1;
1348
1349 if (isChanged) {
1350 if (rtl) {
1351 changedTask.end = dateByX(newX1, selectedTask.x1, selectedTask.end, xStep, timeStep);
1352 } else {
1353 changedTask.start = dateByX(newX1, selectedTask.x1, selectedTask.start, xStep, timeStep);
1354 }
1355
1356 var _progressWithByParams3 = progressWithByParams(changedTask.x1, changedTask.x2, changedTask.progress, rtl),
1357 _progressWidth = _progressWithByParams3[0],
1358 _progressX = _progressWithByParams3[1];
1359
1360 changedTask.progressWidth = _progressWidth;
1361 changedTask.progressX = _progressX;
1362 }
1363
1364 break;
1365 }
1366
1367 case "end":
1368 {
1369 var newX2 = endByX(svgX, xStep, selectedTask);
1370 changedTask.x2 = newX2;
1371 isChanged = changedTask.x2 !== selectedTask.x2;
1372
1373 if (isChanged) {
1374 if (rtl) {
1375 changedTask.start = dateByX(newX2, selectedTask.x2, selectedTask.start, xStep, timeStep);
1376 } else {
1377 changedTask.end = dateByX(newX2, selectedTask.x2, selectedTask.end, xStep, timeStep);
1378 }
1379
1380 var _progressWithByParams4 = progressWithByParams(changedTask.x1, changedTask.x2, changedTask.progress, rtl),
1381 _progressWidth2 = _progressWithByParams4[0],
1382 _progressX2 = _progressWithByParams4[1];
1383
1384 changedTask.progressWidth = _progressWidth2;
1385 changedTask.progressX = _progressX2;
1386 }
1387
1388 break;
1389 }
1390
1391 case "move":
1392 {
1393 var _moveByX = moveByX(svgX - initEventX1Delta, xStep, selectedTask),
1394 newMoveX1 = _moveByX[0],
1395 newMoveX2 = _moveByX[1];
1396
1397 isChanged = newMoveX1 !== selectedTask.x1;
1398
1399 if (isChanged) {
1400 changedTask.start = dateByX(newMoveX1, selectedTask.x1, selectedTask.start, xStep, timeStep);
1401 changedTask.end = dateByX(newMoveX2, selectedTask.x2, selectedTask.end, xStep, timeStep);
1402 changedTask.x1 = newMoveX1;
1403 changedTask.x2 = newMoveX2;
1404
1405 var _progressWithByParams5 = progressWithByParams(changedTask.x1, changedTask.x2, changedTask.progress, rtl),
1406 _progressWidth3 = _progressWithByParams5[0],
1407 _progressX3 = _progressWithByParams5[1];
1408
1409 changedTask.progressWidth = _progressWidth3;
1410 changedTask.progressX = _progressX3;
1411 }
1412
1413 break;
1414 }
1415 }
1416
1417 return {
1418 isChanged: isChanged,
1419 changedTask: changedTask
1420 };
1421};
1422
1423var handleTaskBySVGMouseEventForMilestone = function handleTaskBySVGMouseEventForMilestone(svgX, action, selectedTask, xStep, timeStep, initEventX1Delta) {
1424 var changedTask = _extends({}, selectedTask);
1425
1426 var isChanged = false;
1427
1428 switch (action) {
1429 case "move":
1430 {
1431 var _moveByX2 = moveByX(svgX - initEventX1Delta, xStep, selectedTask),
1432 newMoveX1 = _moveByX2[0],
1433 newMoveX2 = _moveByX2[1];
1434
1435 isChanged = newMoveX1 !== selectedTask.x1;
1436
1437 if (isChanged) {
1438 changedTask.start = dateByX(newMoveX1, selectedTask.x1, selectedTask.start, xStep, timeStep);
1439 changedTask.end = changedTask.start;
1440 changedTask.x1 = newMoveX1;
1441 changedTask.x2 = newMoveX2;
1442 }
1443
1444 break;
1445 }
1446 }
1447
1448 return {
1449 isChanged: isChanged,
1450 changedTask: changedTask
1451 };
1452};
1453
1454function isKeyboardEvent(event) {
1455 return event.key !== undefined;
1456}
1457function removeHiddenTasks(tasks) {
1458 var groupedTasks = tasks.filter(function (t) {
1459 return t.hideChildren && t.type === "project";
1460 });
1461
1462 if (groupedTasks.length > 0) {
1463 var _loop = function _loop(i) {
1464 var groupedTask = groupedTasks[i];
1465 var children = getChildren(tasks, groupedTask);
1466 tasks = tasks.filter(function (t) {
1467 return children.indexOf(t) === -1;
1468 });
1469 };
1470
1471 for (var i = 0; groupedTasks.length > i; i++) {
1472 _loop(i);
1473 }
1474 }
1475
1476 return tasks;
1477}
1478
1479function getChildren(taskList, task) {
1480 var tasks = [];
1481
1482 if (task.type !== "project") {
1483 tasks = taskList.filter(function (t) {
1484 return t.dependencies && t.dependencies.indexOf(task.id) !== -1;
1485 });
1486 } else {
1487 tasks = taskList.filter(function (t) {
1488 return t.project && t.project === task.id;
1489 });
1490 }
1491
1492 var taskChildren = [];
1493 tasks.forEach(function (t) {
1494 taskChildren.push.apply(taskChildren, getChildren(taskList, t));
1495 });
1496 tasks = tasks.concat(tasks, taskChildren);
1497 return tasks;
1498}
1499
1500var sortTasks = function sortTasks(taskA, taskB) {
1501 var orderA = taskA.displayOrder || Number.MAX_VALUE;
1502 var orderB = taskB.displayOrder || Number.MAX_VALUE;
1503
1504 if (orderA > orderB) {
1505 return 1;
1506 } else if (orderA < orderB) {
1507 return -1;
1508 } else {
1509 return 0;
1510 }
1511};
1512
1513var styles$6 = {"barWrapper":"_KxSXS","barHandle":"_3w_5u","barBackground":"_31ERP"};
1514
1515var BarDisplay = function BarDisplay(_ref) {
1516 var x = _ref.x,
1517 y = _ref.y,
1518 width = _ref.width,
1519 height = _ref.height,
1520 isSelected = _ref.isSelected,
1521 progressX = _ref.progressX,
1522 progressWidth = _ref.progressWidth,
1523 barCornerRadius = _ref.barCornerRadius,
1524 styles = _ref.styles,
1525 onMouseDown = _ref.onMouseDown;
1526
1527 var getProcessColor = function getProcessColor() {
1528 return isSelected ? styles.progressSelectedColor : styles.progressColor;
1529 };
1530
1531 var getBarColor = function getBarColor() {
1532 return isSelected ? styles.backgroundSelectedColor : styles.backgroundColor;
1533 };
1534
1535 return React.createElement("g", {
1536 onMouseDown: onMouseDown
1537 }, React.createElement("rect", {
1538 x: x,
1539 width: width,
1540 y: y,
1541 height: height,
1542 ry: barCornerRadius,
1543 rx: barCornerRadius,
1544 fill: getBarColor(),
1545 className: styles$6.barBackground
1546 }), React.createElement("rect", {
1547 x: progressX,
1548 width: progressWidth,
1549 y: y,
1550 height: height,
1551 ry: barCornerRadius,
1552 rx: barCornerRadius,
1553 fill: getProcessColor()
1554 }));
1555};
1556
1557var BarDateHandle = function BarDateHandle(_ref) {
1558 var x = _ref.x,
1559 y = _ref.y,
1560 width = _ref.width,
1561 height = _ref.height,
1562 barCornerRadius = _ref.barCornerRadius,
1563 onMouseDown = _ref.onMouseDown;
1564 return React.createElement("rect", {
1565 x: x,
1566 y: y,
1567 width: width,
1568 height: height,
1569 className: styles$6.barHandle,
1570 ry: barCornerRadius,
1571 rx: barCornerRadius,
1572 onMouseDown: onMouseDown
1573 });
1574};
1575
1576var BarProgressHandle = function BarProgressHandle(_ref) {
1577 var progressPoint = _ref.progressPoint,
1578 onMouseDown = _ref.onMouseDown;
1579 return React.createElement("polygon", {
1580 className: styles$6.barHandle,
1581 points: progressPoint,
1582 onMouseDown: onMouseDown
1583 });
1584};
1585
1586var Bar = function Bar(_ref) {
1587 var task = _ref.task,
1588 isProgressChangeable = _ref.isProgressChangeable,
1589 isDateChangeable = _ref.isDateChangeable,
1590 rtl = _ref.rtl,
1591 onEventStart = _ref.onEventStart,
1592 isSelected = _ref.isSelected;
1593 var progressPoint = getProgressPoint(+!rtl * task.progressWidth + task.progressX, task.y, task.height);
1594 var handleHeight = task.height - 2;
1595 return React.createElement("g", {
1596 className: styles$6.barWrapper,
1597 tabIndex: 0
1598 }, React.createElement(BarDisplay, {
1599 x: task.x1,
1600 y: task.y,
1601 width: task.x2 - task.x1,
1602 height: task.height,
1603 progressX: task.progressX,
1604 progressWidth: task.progressWidth,
1605 barCornerRadius: task.barCornerRadius,
1606 styles: task.styles,
1607 isSelected: isSelected,
1608 onMouseDown: function onMouseDown(e) {
1609 isDateChangeable && onEventStart("move", task, e);
1610 }
1611 }), React.createElement("g", {
1612 className: "handleGroup"
1613 }, isDateChangeable && React.createElement("g", null, React.createElement(BarDateHandle, {
1614 x: task.x1 + 1,
1615 y: task.y + 1,
1616 width: task.handleWidth,
1617 height: handleHeight,
1618 barCornerRadius: task.barCornerRadius,
1619 onMouseDown: function onMouseDown(e) {
1620 onEventStart("start", task, e);
1621 }
1622 }), React.createElement(BarDateHandle, {
1623 x: task.x2 - task.handleWidth - 1,
1624 y: task.y + 1,
1625 width: task.handleWidth,
1626 height: handleHeight,
1627 barCornerRadius: task.barCornerRadius,
1628 onMouseDown: function onMouseDown(e) {
1629 onEventStart("end", task, e);
1630 }
1631 })), isProgressChangeable && React.createElement(BarProgressHandle, {
1632 progressPoint: progressPoint,
1633 onMouseDown: function onMouseDown(e) {
1634 onEventStart("progress", task, e);
1635 }
1636 })));
1637};
1638
1639var BarSmall = function BarSmall(_ref) {
1640 var task = _ref.task,
1641 isProgressChangeable = _ref.isProgressChangeable,
1642 isDateChangeable = _ref.isDateChangeable,
1643 onEventStart = _ref.onEventStart,
1644 isSelected = _ref.isSelected;
1645 var progressPoint = getProgressPoint(task.progressWidth + task.x1, task.y, task.height);
1646 return React.createElement("g", {
1647 className: styles$6.barWrapper,
1648 tabIndex: 0
1649 }, React.createElement(BarDisplay, {
1650 x: task.x1,
1651 y: task.y,
1652 width: task.x2 - task.x1,
1653 height: task.height,
1654 progressX: task.progressX,
1655 progressWidth: task.progressWidth,
1656 barCornerRadius: task.barCornerRadius,
1657 styles: task.styles,
1658 isSelected: isSelected,
1659 onMouseDown: function onMouseDown(e) {
1660 isDateChangeable && onEventStart("move", task, e);
1661 }
1662 }), React.createElement("g", {
1663 className: "handleGroup"
1664 }, isProgressChangeable && React.createElement(BarProgressHandle, {
1665 progressPoint: progressPoint,
1666 onMouseDown: function onMouseDown(e) {
1667 onEventStart("progress", task, e);
1668 }
1669 })));
1670};
1671
1672var styles$7 = {"milestoneWrapper":"_RRr13","milestoneBackground":"_2P2B1"};
1673
1674var Milestone = function Milestone(_ref) {
1675 var task = _ref.task,
1676 isDateChangeable = _ref.isDateChangeable,
1677 onEventStart = _ref.onEventStart,
1678 isSelected = _ref.isSelected;
1679 var transform = "rotate(45 " + (task.x1 + task.height * 0.356) + " \n " + (task.y + task.height * 0.85) + ")";
1680
1681 var getBarColor = function getBarColor() {
1682 return isSelected ? task.styles.backgroundSelectedColor : task.styles.backgroundColor;
1683 };
1684
1685 return React.createElement("g", {
1686 tabIndex: 0,
1687 className: styles$7.milestoneWrapper
1688 }, React.createElement("rect", {
1689 fill: getBarColor(),
1690 x: task.x1,
1691 width: task.height,
1692 y: task.y,
1693 height: task.height,
1694 rx: task.barCornerRadius,
1695 ry: task.barCornerRadius,
1696 transform: transform,
1697 className: styles$7.milestoneBackground,
1698 onMouseDown: function onMouseDown(e) {
1699 isDateChangeable && onEventStart("move", task, e);
1700 }
1701 }));
1702};
1703
1704var styles$8 = {"projectWrapper":"_1KJ6x","projectBackground":"_2RbVy","projectTop":"_2pZMF"};
1705
1706var Project = function Project(_ref) {
1707 var task = _ref.task,
1708 isSelected = _ref.isSelected;
1709 var barColor = isSelected ? task.styles.backgroundSelectedColor : task.styles.backgroundColor;
1710 var processColor = isSelected ? task.styles.progressSelectedColor : task.styles.progressColor;
1711 var projectWith = task.x2 - task.x1;
1712 var projectLeftTriangle = [task.x1, task.y + task.height / 2 - 1, task.x1, task.y + task.height, task.x1 + 15, task.y + task.height / 2 - 1].join(",");
1713 var projectRightTriangle = [task.x2, task.y + task.height / 2 - 1, task.x2, task.y + task.height, task.x2 - 15, task.y + task.height / 2 - 1].join(",");
1714 return React.createElement("g", {
1715 tabIndex: 0,
1716 className: styles$8.projectWrapper
1717 }, React.createElement("rect", {
1718 fill: barColor,
1719 x: task.x1,
1720 width: projectWith,
1721 y: task.y,
1722 height: task.height,
1723 rx: task.barCornerRadius,
1724 ry: task.barCornerRadius,
1725 className: styles$8.projectBackground
1726 }), React.createElement("rect", {
1727 x: task.progressX,
1728 width: task.progressWidth,
1729 y: task.y,
1730 height: task.height,
1731 ry: task.barCornerRadius,
1732 rx: task.barCornerRadius,
1733 fill: processColor
1734 }), React.createElement("rect", {
1735 fill: barColor,
1736 x: task.x1,
1737 width: projectWith,
1738 y: task.y,
1739 height: task.height / 2,
1740 rx: task.barCornerRadius,
1741 ry: task.barCornerRadius,
1742 className: styles$8.projectTop
1743 }), React.createElement("polygon", {
1744 className: styles$8.projectTop,
1745 points: projectLeftTriangle,
1746 fill: barColor
1747 }), React.createElement("polygon", {
1748 className: styles$8.projectTop,
1749 points: projectRightTriangle,
1750 fill: barColor
1751 }));
1752};
1753
1754var style = {"barLabel":"_3zRJQ","barLabelOutside":"_3KcaM"};
1755
1756var TaskItem = function TaskItem(props) {
1757 var _props = _extends({}, props),
1758 task = _props.task,
1759 arrowIndent = _props.arrowIndent,
1760 isDelete = _props.isDelete,
1761 taskHeight = _props.taskHeight,
1762 isSelected = _props.isSelected,
1763 rtl = _props.rtl,
1764 onEventStart = _props.onEventStart;
1765
1766 var textRef = useRef(null);
1767
1768 var _useState = useState(React.createElement("div", null)),
1769 taskItem = _useState[0],
1770 setTaskItem = _useState[1];
1771
1772 var _useState2 = useState(true),
1773 isTextInside = _useState2[0],
1774 setIsTextInside = _useState2[1];
1775
1776 useEffect(function () {
1777 switch (task.typeInternal) {
1778 case "milestone":
1779 setTaskItem(React.createElement(Milestone, Object.assign({}, props)));
1780 break;
1781
1782 case "project":
1783 setTaskItem(React.createElement(Project, Object.assign({}, props)));
1784 break;
1785
1786 case "smalltask":
1787 setTaskItem(React.createElement(BarSmall, Object.assign({}, props)));
1788 break;
1789
1790 default:
1791 setTaskItem(React.createElement(Bar, Object.assign({}, props)));
1792 break;
1793 }
1794 }, [task, isSelected]);
1795 useEffect(function () {
1796 if (textRef.current) {
1797 setIsTextInside(textRef.current.getBBox().width < task.x2 - task.x1);
1798 }
1799 }, [textRef, task]);
1800
1801 var getX = function getX() {
1802 var width = task.x2 - task.x1;
1803 var hasChild = task.barChildren.length > 0;
1804
1805 if (isTextInside) {
1806 return task.x1 + width * 0.5;
1807 }
1808
1809 if (rtl && textRef.current) {
1810 return task.x1 - textRef.current.getBBox().width - arrowIndent * +hasChild - arrowIndent * 0.2;
1811 } else {
1812 return task.x1 + width + arrowIndent * +hasChild + arrowIndent * 0.2;
1813 }
1814 };
1815
1816 return React.createElement("g", {
1817 onKeyDown: function onKeyDown(e) {
1818 switch (e.key) {
1819 case "Delete":
1820 {
1821 if (isDelete) onEventStart("delete", task, e);
1822 break;
1823 }
1824 }
1825
1826 e.stopPropagation();
1827 },
1828 onMouseEnter: function onMouseEnter(e) {
1829 onEventStart("mouseenter", task, e);
1830 },
1831 onMouseLeave: function onMouseLeave(e) {
1832 onEventStart("mouseleave", task, e);
1833 },
1834 onDoubleClick: function onDoubleClick(e) {
1835 onEventStart("dblclick", task, e);
1836 },
1837 onClick: function onClick(e) {
1838 onEventStart("click", task, e);
1839 },
1840 onFocus: function onFocus() {
1841 onEventStart("select", task);
1842 }
1843 }, taskItem, React.createElement("text", {
1844 x: getX(),
1845 y: task.y + taskHeight * 0.5,
1846 className: isTextInside ? style.barLabel : style.barLabelOutside,
1847 ref: textRef
1848 }, task.name));
1849};
1850
1851var TaskGanttContent = function TaskGanttContent(_ref) {
1852 var _svg$current;
1853
1854 var tasks = _ref.tasks,
1855 dates = _ref.dates,
1856 ganttEvent = _ref.ganttEvent,
1857 selectedTask = _ref.selectedTask,
1858 rowHeight = _ref.rowHeight,
1859 columnWidth = _ref.columnWidth,
1860 timeStep = _ref.timeStep,
1861 svg = _ref.svg,
1862 taskHeight = _ref.taskHeight,
1863 arrowColor = _ref.arrowColor,
1864 arrowIndent = _ref.arrowIndent,
1865 fontFamily = _ref.fontFamily,
1866 fontSize = _ref.fontSize,
1867 rtl = _ref.rtl,
1868 setGanttEvent = _ref.setGanttEvent,
1869 setFailedTask = _ref.setFailedTask,
1870 setSelectedTask = _ref.setSelectedTask,
1871 onDateChange = _ref.onDateChange,
1872 onProgressChange = _ref.onProgressChange,
1873 onDoubleClick = _ref.onDoubleClick,
1874 onClick = _ref.onClick,
1875 onDelete = _ref.onDelete;
1876 var point = svg === null || svg === void 0 ? void 0 : (_svg$current = svg.current) === null || _svg$current === void 0 ? void 0 : _svg$current.createSVGPoint();
1877
1878 var _useState = useState(0),
1879 xStep = _useState[0],
1880 setXStep = _useState[1];
1881
1882 var _useState2 = useState(0),
1883 initEventX1Delta = _useState2[0],
1884 setInitEventX1Delta = _useState2[1];
1885
1886 var _useState3 = useState(false),
1887 isMoving = _useState3[0],
1888 setIsMoving = _useState3[1];
1889
1890 useEffect(function () {
1891 var dateDelta = dates[1].getTime() - dates[0].getTime() - dates[1].getTimezoneOffset() * 60 * 1000 + dates[0].getTimezoneOffset() * 60 * 1000;
1892 var newXStep = timeStep * columnWidth / dateDelta;
1893 setXStep(newXStep);
1894 }, [columnWidth, dates, timeStep]);
1895 useEffect(function () {
1896 var handleMouseMove = function handleMouseMove(event) {
1897 try {
1898 var _svg$current$getScree;
1899
1900 if (!ganttEvent.changedTask || !point || !(svg !== null && svg !== void 0 && svg.current)) return Promise.resolve();
1901 event.preventDefault();
1902 point.x = event.clientX;
1903 var cursor = point.matrixTransform(svg === null || svg === void 0 ? void 0 : (_svg$current$getScree = svg.current.getScreenCTM()) === null || _svg$current$getScree === void 0 ? void 0 : _svg$current$getScree.inverse());
1904
1905 var _handleTaskBySVGMouse = handleTaskBySVGMouseEvent(cursor.x, ganttEvent.action, ganttEvent.changedTask, xStep, timeStep, initEventX1Delta, rtl),
1906 isChanged = _handleTaskBySVGMouse.isChanged,
1907 changedTask = _handleTaskBySVGMouse.changedTask;
1908
1909 if (isChanged) {
1910 setGanttEvent({
1911 action: ganttEvent.action,
1912 changedTask: changedTask
1913 });
1914 }
1915
1916 return Promise.resolve();
1917 } catch (e) {
1918 return Promise.reject(e);
1919 }
1920 };
1921
1922 var handleMouseUp = function handleMouseUp(event) {
1923 try {
1924 var _svg$current$getScree2;
1925
1926 var _temp6 = function _temp6() {
1927 if (!operationSuccess) {
1928 setFailedTask(originalSelectedTask);
1929 }
1930 };
1931
1932 var action = ganttEvent.action,
1933 originalSelectedTask = ganttEvent.originalSelectedTask,
1934 changedTask = ganttEvent.changedTask;
1935 if (!changedTask || !point || !(svg !== null && svg !== void 0 && svg.current) || !originalSelectedTask) return Promise.resolve();
1936 event.preventDefault();
1937 point.x = event.clientX;
1938 var cursor = point.matrixTransform(svg === null || svg === void 0 ? void 0 : (_svg$current$getScree2 = svg.current.getScreenCTM()) === null || _svg$current$getScree2 === void 0 ? void 0 : _svg$current$getScree2.inverse());
1939
1940 var _handleTaskBySVGMouse2 = handleTaskBySVGMouseEvent(cursor.x, action, changedTask, xStep, timeStep, initEventX1Delta, rtl),
1941 newChangedTask = _handleTaskBySVGMouse2.changedTask;
1942
1943 var isNotLikeOriginal = originalSelectedTask.start !== newChangedTask.start || originalSelectedTask.end !== newChangedTask.end || originalSelectedTask.progress !== newChangedTask.progress;
1944 svg.current.removeEventListener("mousemove", handleMouseMove);
1945 svg.current.removeEventListener("mouseup", handleMouseUp);
1946 setGanttEvent({
1947 action: ""
1948 });
1949 setIsMoving(false);
1950 var operationSuccess = true;
1951
1952 var _temp7 = function () {
1953 if ((action === "move" || action === "end" || action === "start") && onDateChange && isNotLikeOriginal) {
1954 var _temp8 = _catch(function () {
1955 return Promise.resolve(onDateChange(newChangedTask, newChangedTask.barChildren)).then(function (result) {
1956 if (result !== undefined) {
1957 operationSuccess = result;
1958 }
1959 });
1960 }, function () {
1961 operationSuccess = false;
1962 });
1963
1964 if (_temp8 && _temp8.then) return _temp8.then(function () {});
1965 } else {
1966 var _temp9 = function () {
1967 if (onProgressChange && isNotLikeOriginal) {
1968 var _temp10 = _catch(function () {
1969 return Promise.resolve(onProgressChange(newChangedTask, newChangedTask.barChildren)).then(function (result) {
1970 if (result !== undefined) {
1971 operationSuccess = result;
1972 }
1973 });
1974 }, function () {
1975 operationSuccess = false;
1976 });
1977
1978 if (_temp10 && _temp10.then) return _temp10.then(function () {});
1979 }
1980 }();
1981
1982 if (_temp9 && _temp9.then) return _temp9.then(function () {});
1983 }
1984 }();
1985
1986 return Promise.resolve(_temp7 && _temp7.then ? _temp7.then(_temp6) : _temp6(_temp7));
1987 } catch (e) {
1988 return Promise.reject(e);
1989 }
1990 };
1991
1992 if (!isMoving && (ganttEvent.action === "move" || ganttEvent.action === "end" || ganttEvent.action === "start" || ganttEvent.action === "progress") && svg !== null && svg !== void 0 && svg.current) {
1993 svg.current.addEventListener("mousemove", handleMouseMove);
1994 svg.current.addEventListener("mouseup", handleMouseUp);
1995 setIsMoving(true);
1996 }
1997 }, [ganttEvent, xStep, initEventX1Delta, onProgressChange, timeStep, onDateChange, svg, isMoving, point, rtl, setFailedTask, setGanttEvent]);
1998
1999 var handleBarEventStart = function handleBarEventStart(action, task, event) {
2000 try {
2001 return Promise.resolve(function () {
2002 if (!event) {
2003 if (action === "select") {
2004 setSelectedTask(task.id);
2005 }
2006 } else return function () {
2007 if (isKeyboardEvent(event)) {
2008 var _temp14 = function () {
2009 if (action === "delete") {
2010 var _temp15 = function () {
2011 if (onDelete) {
2012 var _temp16 = _catch(function () {
2013 return Promise.resolve(onDelete(task)).then(function (result) {
2014 if (result !== undefined && result) {
2015 setGanttEvent({
2016 action: action,
2017 changedTask: task
2018 });
2019 }
2020 });
2021 }, function (error) {
2022 console.error("Error on Delete. " + error);
2023 });
2024
2025 if (_temp16 && _temp16.then) return _temp16.then(function () {});
2026 }
2027 }();
2028
2029 if (_temp15 && _temp15.then) return _temp15.then(function () {});
2030 }
2031 }();
2032
2033 if (_temp14 && _temp14.then) return _temp14.then(function () {});
2034 } else if (action === "mouseenter") {
2035 if (!ganttEvent.action) {
2036 setGanttEvent({
2037 action: action,
2038 changedTask: task,
2039 originalSelectedTask: task
2040 });
2041 }
2042 } else if (action === "mouseleave") {
2043 if (ganttEvent.action === "mouseenter") {
2044 setGanttEvent({
2045 action: ""
2046 });
2047 }
2048 } else if (action === "dblclick") {
2049 !!onDoubleClick && onDoubleClick(task);
2050 } else if (action === "click") {
2051 !!onClick && onClick(task);
2052 } else if (action === "move") {
2053 var _svg$current$getScree3;
2054
2055 if (!(svg !== null && svg !== void 0 && svg.current) || !point) return;
2056 point.x = event.clientX;
2057 var cursor = point.matrixTransform((_svg$current$getScree3 = svg.current.getScreenCTM()) === null || _svg$current$getScree3 === void 0 ? void 0 : _svg$current$getScree3.inverse());
2058 setInitEventX1Delta(cursor.x - task.x1);
2059 setGanttEvent({
2060 action: action,
2061 changedTask: task,
2062 originalSelectedTask: task
2063 });
2064 } else {
2065 setGanttEvent({
2066 action: action,
2067 changedTask: task,
2068 originalSelectedTask: task
2069 });
2070 }
2071 }();
2072 }());
2073 } catch (e) {
2074 return Promise.reject(e);
2075 }
2076 };
2077
2078 return React.createElement("g", {
2079 className: "content"
2080 }, React.createElement("g", {
2081 className: "arrows",
2082 fill: arrowColor,
2083 stroke: arrowColor
2084 }, tasks.map(function (task) {
2085 return task.barChildren.map(function (child) {
2086 return React.createElement(Arrow, {
2087 key: "Arrow from " + task.id + " to " + tasks[child.index].id,
2088 taskFrom: task,
2089 taskTo: tasks[child.index],
2090 rowHeight: rowHeight,
2091 taskHeight: taskHeight,
2092 arrowIndent: arrowIndent,
2093 rtl: rtl
2094 });
2095 });
2096 })), React.createElement("g", {
2097 className: "bar",
2098 fontFamily: fontFamily,
2099 fontSize: fontSize
2100 }, tasks.map(function (task) {
2101 return React.createElement(TaskItem, {
2102 task: task,
2103 arrowIndent: arrowIndent,
2104 taskHeight: taskHeight,
2105 isProgressChangeable: !!onProgressChange && !task.isDisabled,
2106 isDateChangeable: !!onDateChange && !task.isDisabled,
2107 isDelete: !task.isDisabled,
2108 onEventStart: handleBarEventStart,
2109 key: task.id,
2110 isSelected: !!selectedTask && task.id === selectedTask.id,
2111 rtl: rtl
2112 });
2113 })));
2114};
2115
2116var styles$9 = {"ganttVerticalContainer":"_CZjuD","horizontalContainer":"_2B2zv","wrapper":"_3eULf"};
2117
2118var TaskGantt = function TaskGantt(_ref) {
2119 var gridProps = _ref.gridProps,
2120 calendarProps = _ref.calendarProps,
2121 barProps = _ref.barProps,
2122 ganttHeight = _ref.ganttHeight,
2123 scrollY = _ref.scrollY,
2124 scrollX = _ref.scrollX;
2125 var ganttSVGRef = useRef(null);
2126 var horizontalContainerRef = useRef(null);
2127 var verticalGanttContainerRef = useRef(null);
2128
2129 var newBarProps = _extends({}, barProps, {
2130 svg: ganttSVGRef
2131 });
2132
2133 useEffect(function () {
2134 if (horizontalContainerRef.current) {
2135 horizontalContainerRef.current.scrollTop = scrollY;
2136 }
2137 }, [scrollY]);
2138 useEffect(function () {
2139 if (verticalGanttContainerRef.current) {
2140 verticalGanttContainerRef.current.scrollLeft = scrollX;
2141 }
2142 }, [scrollX]);
2143 return React.createElement("div", {
2144 className: styles$9.ganttVerticalContainer,
2145 ref: verticalGanttContainerRef,
2146 dir: "ltr"
2147 }, React.createElement("svg", {
2148 xmlns: "http://www.w3.org/2000/svg",
2149 width: gridProps.svgWidth,
2150 height: calendarProps.headerHeight,
2151 fontFamily: barProps.fontFamily
2152 }, React.createElement(Calendar, Object.assign({}, calendarProps))), React.createElement("div", {
2153 ref: horizontalContainerRef,
2154 className: styles$9.horizontalContainer,
2155 style: ganttHeight ? {
2156 height: ganttHeight,
2157 width: gridProps.svgWidth
2158 } : {
2159 width: gridProps.svgWidth
2160 }
2161 }, React.createElement("svg", {
2162 xmlns: "http://www.w3.org/2000/svg",
2163 width: gridProps.svgWidth,
2164 height: barProps.rowHeight * barProps.tasks.length,
2165 fontFamily: barProps.fontFamily,
2166 ref: ganttSVGRef
2167 }, React.createElement(Grid, Object.assign({}, gridProps)), React.createElement(TaskGanttContent, Object.assign({}, newBarProps)))));
2168};
2169
2170var styles$a = {"scrollWrapper":"_2k9Ys","scroll":"_19jgW"};
2171
2172var HorizontalScroll = function HorizontalScroll(_ref) {
2173 var scroll = _ref.scroll,
2174 svgWidth = _ref.svgWidth,
2175 taskListWidth = _ref.taskListWidth,
2176 rtl = _ref.rtl,
2177 onScroll = _ref.onScroll;
2178 var scrollRef = useRef(null);
2179 useEffect(function () {
2180 if (scrollRef.current) {
2181 scrollRef.current.scrollLeft = scroll;
2182 }
2183 }, [scroll]);
2184 return React.createElement("div", {
2185 dir: "ltr",
2186 style: {
2187 margin: rtl ? "0px " + taskListWidth + "px 0px 0px" : "0px 0px 0px " + taskListWidth + "px"
2188 },
2189 className: styles$a.scrollWrapper,
2190 onScroll: onScroll,
2191 ref: scrollRef
2192 }, React.createElement("div", {
2193 style: {
2194 width: svgWidth
2195 },
2196 className: styles$a.scroll
2197 }));
2198};
2199
2200var Gantt = function Gantt(_ref) {
2201 var tasks = _ref.tasks,
2202 _ref$headerHeight = _ref.headerHeight,
2203 headerHeight = _ref$headerHeight === void 0 ? 50 : _ref$headerHeight,
2204 _ref$columnWidth = _ref.columnWidth,
2205 columnWidth = _ref$columnWidth === void 0 ? 60 : _ref$columnWidth,
2206 _ref$listCellWidth = _ref.listCellWidth,
2207 listCellWidth = _ref$listCellWidth === void 0 ? "155px" : _ref$listCellWidth,
2208 _ref$rowHeight = _ref.rowHeight,
2209 rowHeight = _ref$rowHeight === void 0 ? 50 : _ref$rowHeight,
2210 _ref$ganttHeight = _ref.ganttHeight,
2211 ganttHeight = _ref$ganttHeight === void 0 ? 0 : _ref$ganttHeight,
2212 _ref$viewMode = _ref.viewMode,
2213 viewMode = _ref$viewMode === void 0 ? ViewMode.Day : _ref$viewMode,
2214 _ref$preStepsCount = _ref.preStepsCount,
2215 preStepsCount = _ref$preStepsCount === void 0 ? 1 : _ref$preStepsCount,
2216 _ref$locale = _ref.locale,
2217 locale = _ref$locale === void 0 ? "en-GB" : _ref$locale,
2218 _ref$barFill = _ref.barFill,
2219 barFill = _ref$barFill === void 0 ? 60 : _ref$barFill,
2220 _ref$barCornerRadius = _ref.barCornerRadius,
2221 barCornerRadius = _ref$barCornerRadius === void 0 ? 3 : _ref$barCornerRadius,
2222 _ref$barProgressColor = _ref.barProgressColor,
2223 barProgressColor = _ref$barProgressColor === void 0 ? "#a3a3ff" : _ref$barProgressColor,
2224 _ref$barProgressSelec = _ref.barProgressSelectedColor,
2225 barProgressSelectedColor = _ref$barProgressSelec === void 0 ? "#8282f5" : _ref$barProgressSelec,
2226 _ref$barBackgroundCol = _ref.barBackgroundColor,
2227 barBackgroundColor = _ref$barBackgroundCol === void 0 ? "#b8c2cc" : _ref$barBackgroundCol,
2228 _ref$barBackgroundSel = _ref.barBackgroundSelectedColor,
2229 barBackgroundSelectedColor = _ref$barBackgroundSel === void 0 ? "#aeb8c2" : _ref$barBackgroundSel,
2230 _ref$projectProgressC = _ref.projectProgressColor,
2231 projectProgressColor = _ref$projectProgressC === void 0 ? "#7db59a" : _ref$projectProgressC,
2232 _ref$projectProgressS = _ref.projectProgressSelectedColor,
2233 projectProgressSelectedColor = _ref$projectProgressS === void 0 ? "#59a985" : _ref$projectProgressS,
2234 _ref$projectBackgroun = _ref.projectBackgroundColor,
2235 projectBackgroundColor = _ref$projectBackgroun === void 0 ? "#fac465" : _ref$projectBackgroun,
2236 _ref$projectBackgroun2 = _ref.projectBackgroundSelectedColor,
2237 projectBackgroundSelectedColor = _ref$projectBackgroun2 === void 0 ? "#f7bb53" : _ref$projectBackgroun2,
2238 _ref$milestoneBackgro = _ref.milestoneBackgroundColor,
2239 milestoneBackgroundColor = _ref$milestoneBackgro === void 0 ? "#f1c453" : _ref$milestoneBackgro,
2240 _ref$milestoneBackgro2 = _ref.milestoneBackgroundSelectedColor,
2241 milestoneBackgroundSelectedColor = _ref$milestoneBackgro2 === void 0 ? "#f29e4c" : _ref$milestoneBackgro2,
2242 _ref$rtl = _ref.rtl,
2243 rtl = _ref$rtl === void 0 ? false : _ref$rtl,
2244 _ref$handleWidth = _ref.handleWidth,
2245 handleWidth = _ref$handleWidth === void 0 ? 8 : _ref$handleWidth,
2246 _ref$timeStep = _ref.timeStep,
2247 timeStep = _ref$timeStep === void 0 ? 300000 : _ref$timeStep,
2248 _ref$arrowColor = _ref.arrowColor,
2249 arrowColor = _ref$arrowColor === void 0 ? "grey" : _ref$arrowColor,
2250 _ref$fontFamily = _ref.fontFamily,
2251 fontFamily = _ref$fontFamily === void 0 ? "Arial, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue" : _ref$fontFamily,
2252 _ref$fontSize = _ref.fontSize,
2253 fontSize = _ref$fontSize === void 0 ? "14px" : _ref$fontSize,
2254 _ref$arrowIndent = _ref.arrowIndent,
2255 arrowIndent = _ref$arrowIndent === void 0 ? 20 : _ref$arrowIndent,
2256 _ref$todayColor = _ref.todayColor,
2257 todayColor = _ref$todayColor === void 0 ? "rgba(252, 248, 227, 0.5)" : _ref$todayColor,
2258 viewDate = _ref.viewDate,
2259 _ref$TooltipContent = _ref.TooltipContent,
2260 TooltipContent = _ref$TooltipContent === void 0 ? StandardTooltipContent : _ref$TooltipContent,
2261 _ref$TaskListHeader = _ref.TaskListHeader,
2262 TaskListHeader = _ref$TaskListHeader === void 0 ? TaskListHeaderDefault : _ref$TaskListHeader,
2263 _ref$TaskListTable = _ref.TaskListTable,
2264 TaskListTable = _ref$TaskListTable === void 0 ? TaskListTableDefault : _ref$TaskListTable,
2265 onDateChange = _ref.onDateChange,
2266 onProgressChange = _ref.onProgressChange,
2267 onDoubleClick = _ref.onDoubleClick,
2268 onClick = _ref.onClick,
2269 onDelete = _ref.onDelete,
2270 onSelect = _ref.onSelect,
2271 onExpanderClick = _ref.onExpanderClick;
2272 var wrapperRef = useRef(null);
2273 var taskListRef = useRef(null);
2274
2275 var _useState = useState(function () {
2276 var _ganttDateRange = ganttDateRange(tasks, viewMode, preStepsCount),
2277 startDate = _ganttDateRange[0],
2278 endDate = _ganttDateRange[1];
2279
2280 return {
2281 viewMode: viewMode,
2282 dates: seedDates(startDate, endDate, viewMode)
2283 };
2284 }),
2285 dateSetup = _useState[0],
2286 setDateSetup = _useState[1];
2287
2288 var _useState2 = useState(undefined),
2289 currentViewDate = _useState2[0],
2290 setCurrentViewDate = _useState2[1];
2291
2292 var _useState3 = useState(0),
2293 taskListWidth = _useState3[0],
2294 setTaskListWidth = _useState3[1];
2295
2296 var _useState4 = useState(0),
2297 svgContainerWidth = _useState4[0],
2298 setSvgContainerWidth = _useState4[1];
2299
2300 var _useState5 = useState(ganttHeight),
2301 svgContainerHeight = _useState5[0],
2302 setSvgContainerHeight = _useState5[1];
2303
2304 var _useState6 = useState([]),
2305 barTasks = _useState6[0],
2306 setBarTasks = _useState6[1];
2307
2308 var _useState7 = useState({
2309 action: ""
2310 }),
2311 ganttEvent = _useState7[0],
2312 setGanttEvent = _useState7[1];
2313
2314 var taskHeight = useMemo(function () {
2315 return rowHeight * barFill / 100;
2316 }, [rowHeight, barFill]);
2317
2318 var _useState8 = useState(),
2319 selectedTask = _useState8[0],
2320 setSelectedTask = _useState8[1];
2321
2322 var _useState9 = useState(null),
2323 failedTask = _useState9[0],
2324 setFailedTask = _useState9[1];
2325
2326 var svgWidth = dateSetup.dates.length * columnWidth;
2327 var ganttFullHeight = barTasks.length * rowHeight;
2328
2329 var _useState10 = useState(0),
2330 scrollY = _useState10[0],
2331 setScrollY = _useState10[1];
2332
2333 var _useState11 = useState(-1),
2334 scrollX = _useState11[0],
2335 setScrollX = _useState11[1];
2336
2337 var _useState12 = useState(false),
2338 ignoreScrollEvent = _useState12[0],
2339 setIgnoreScrollEvent = _useState12[1];
2340
2341 useEffect(function () {
2342 var filteredTasks;
2343
2344 if (onExpanderClick) {
2345 filteredTasks = removeHiddenTasks(tasks);
2346 } else {
2347 filteredTasks = tasks;
2348 }
2349
2350 filteredTasks = filteredTasks.sort(sortTasks);
2351
2352 var _ganttDateRange2 = ganttDateRange(filteredTasks, viewMode, preStepsCount),
2353 startDate = _ganttDateRange2[0],
2354 endDate = _ganttDateRange2[1];
2355
2356 var newDates = seedDates(startDate, endDate, viewMode);
2357
2358 if (rtl) {
2359 newDates = newDates.reverse();
2360
2361 if (scrollX === -1) {
2362 setScrollX(newDates.length * columnWidth);
2363 }
2364 }
2365
2366 setDateSetup({
2367 dates: newDates,
2368 viewMode: viewMode
2369 });
2370 setBarTasks(convertToBarTasks(filteredTasks, newDates, columnWidth, rowHeight, taskHeight, barCornerRadius, handleWidth, rtl, barProgressColor, barProgressSelectedColor, barBackgroundColor, barBackgroundSelectedColor, projectProgressColor, projectProgressSelectedColor, projectBackgroundColor, projectBackgroundSelectedColor, milestoneBackgroundColor, milestoneBackgroundSelectedColor));
2371 }, [tasks, viewMode, preStepsCount, rowHeight, barCornerRadius, columnWidth, taskHeight, handleWidth, barProgressColor, barProgressSelectedColor, barBackgroundColor, barBackgroundSelectedColor, projectProgressColor, projectProgressSelectedColor, projectBackgroundColor, projectBackgroundSelectedColor, milestoneBackgroundColor, milestoneBackgroundSelectedColor, rtl, scrollX, onExpanderClick]);
2372 useEffect(function () {
2373 if (viewMode === dateSetup.viewMode && (viewDate && !currentViewDate || viewDate && (currentViewDate === null || currentViewDate === void 0 ? void 0 : currentViewDate.valueOf()) !== viewDate.valueOf())) {
2374 var dates = dateSetup.dates;
2375 var index = dates.findIndex(function (d, i) {
2376 return viewDate.valueOf() >= d.valueOf() && i + 1 !== dates.length && viewDate.valueOf() < dates[i + 1].valueOf();
2377 });
2378
2379 if (index === -1) {
2380 return;
2381 }
2382
2383 setCurrentViewDate(viewDate);
2384 setScrollX(columnWidth * index);
2385 }
2386 }, [viewDate, columnWidth, dateSetup.dates, dateSetup.viewMode, viewMode, currentViewDate, setCurrentViewDate]);
2387 useEffect(function () {
2388 var changedTask = ganttEvent.changedTask,
2389 action = ganttEvent.action;
2390
2391 if (changedTask) {
2392 if (action === "delete") {
2393 setGanttEvent({
2394 action: ""
2395 });
2396 setBarTasks(barTasks.filter(function (t) {
2397 return t.id !== changedTask.id;
2398 }));
2399 } else if (action === "move" || action === "end" || action === "start" || action === "progress") {
2400 var prevStateTask = barTasks.find(function (t) {
2401 return t.id === changedTask.id;
2402 });
2403
2404 if (prevStateTask && (prevStateTask.start.getTime() !== changedTask.start.getTime() || prevStateTask.end.getTime() !== changedTask.end.getTime() || prevStateTask.progress !== changedTask.progress)) {
2405 var newTaskList = barTasks.map(function (t) {
2406 return t.id === changedTask.id ? changedTask : t;
2407 });
2408 setBarTasks(newTaskList);
2409 }
2410 }
2411 }
2412 }, [ganttEvent, barTasks]);
2413 useEffect(function () {
2414 if (failedTask) {
2415 setBarTasks(barTasks.map(function (t) {
2416 return t.id !== failedTask.id ? t : failedTask;
2417 }));
2418 setFailedTask(null);
2419 }
2420 }, [failedTask, barTasks]);
2421 useEffect(function () {
2422 if (!listCellWidth) {
2423 setTaskListWidth(0);
2424 }
2425
2426 if (taskListRef.current) {
2427 setTaskListWidth(taskListRef.current.offsetWidth);
2428 }
2429 }, [taskListRef, listCellWidth]);
2430 useEffect(function () {
2431 if (wrapperRef.current) {
2432 setSvgContainerWidth(wrapperRef.current.offsetWidth - taskListWidth);
2433 }
2434 }, [wrapperRef, taskListWidth]);
2435 useEffect(function () {
2436 if (ganttHeight) {
2437 setSvgContainerHeight(ganttHeight + headerHeight);
2438 } else {
2439 setSvgContainerHeight(tasks.length * rowHeight + headerHeight);
2440 }
2441 }, [ganttHeight, tasks, headerHeight, rowHeight]);
2442 useEffect(function () {
2443 var _wrapperRef$current;
2444
2445 var handleWheel = function handleWheel(event) {
2446 if (event.shiftKey || event.deltaX) {
2447 var scrollMove = event.deltaX ? event.deltaX : event.deltaY;
2448 var newScrollX = scrollX + scrollMove;
2449
2450 if (newScrollX < 0) {
2451 newScrollX = 0;
2452 } else if (newScrollX > svgWidth) {
2453 newScrollX = svgWidth;
2454 }
2455
2456 setScrollX(newScrollX);
2457 event.preventDefault();
2458 } else if (ganttHeight) {
2459 var newScrollY = scrollY + event.deltaY;
2460
2461 if (newScrollY < 0) {
2462 newScrollY = 0;
2463 } else if (newScrollY > ganttFullHeight - ganttHeight) {
2464 newScrollY = ganttFullHeight - ganttHeight;
2465 }
2466
2467 if (newScrollY !== scrollY) {
2468 setScrollY(newScrollY);
2469 event.preventDefault();
2470 }
2471 }
2472
2473 setIgnoreScrollEvent(true);
2474 };
2475
2476 (_wrapperRef$current = wrapperRef.current) === null || _wrapperRef$current === void 0 ? void 0 : _wrapperRef$current.addEventListener("wheel", handleWheel, {
2477 passive: false
2478 });
2479 return function () {
2480 var _wrapperRef$current2;
2481
2482 (_wrapperRef$current2 = wrapperRef.current) === null || _wrapperRef$current2 === void 0 ? void 0 : _wrapperRef$current2.removeEventListener("wheel", handleWheel);
2483 };
2484 }, [wrapperRef, scrollY, scrollX, ganttHeight, svgWidth, rtl, ganttFullHeight]);
2485
2486 var handleScrollY = function handleScrollY(event) {
2487 if (scrollY !== event.currentTarget.scrollTop && !ignoreScrollEvent) {
2488 setScrollY(event.currentTarget.scrollTop);
2489 setIgnoreScrollEvent(true);
2490 } else {
2491 setIgnoreScrollEvent(false);
2492 }
2493 };
2494
2495 var handleScrollX = function handleScrollX(event) {
2496 if (scrollX !== event.currentTarget.scrollLeft && !ignoreScrollEvent) {
2497 setScrollX(event.currentTarget.scrollLeft);
2498 setIgnoreScrollEvent(true);
2499 } else {
2500 setIgnoreScrollEvent(false);
2501 }
2502 };
2503
2504 var handleKeyDown = function handleKeyDown(event) {
2505 event.preventDefault();
2506 var newScrollY = scrollY;
2507 var newScrollX = scrollX;
2508 var isX = true;
2509
2510 switch (event.key) {
2511 case "Down":
2512 case "ArrowDown":
2513 newScrollY += rowHeight;
2514 isX = false;
2515 break;
2516
2517 case "Up":
2518 case "ArrowUp":
2519 newScrollY -= rowHeight;
2520 isX = false;
2521 break;
2522
2523 case "Left":
2524 case "ArrowLeft":
2525 newScrollX -= columnWidth;
2526 break;
2527
2528 case "Right":
2529 case "ArrowRight":
2530 newScrollX += columnWidth;
2531 break;
2532 }
2533
2534 if (isX) {
2535 if (newScrollX < 0) {
2536 newScrollX = 0;
2537 } else if (newScrollX > svgWidth) {
2538 newScrollX = svgWidth;
2539 }
2540
2541 setScrollX(newScrollX);
2542 } else {
2543 if (newScrollY < 0) {
2544 newScrollY = 0;
2545 } else if (newScrollY > ganttFullHeight - ganttHeight) {
2546 newScrollY = ganttFullHeight - ganttHeight;
2547 }
2548
2549 setScrollY(newScrollY);
2550 }
2551
2552 setIgnoreScrollEvent(true);
2553 };
2554
2555 var handleSelectedTask = function handleSelectedTask(taskId) {
2556 var newSelectedTask = barTasks.find(function (t) {
2557 return t.id === taskId;
2558 });
2559 var oldSelectedTask = barTasks.find(function (t) {
2560 return !!selectedTask && t.id === selectedTask.id;
2561 });
2562
2563 if (onSelect) {
2564 if (oldSelectedTask) {
2565 onSelect(oldSelectedTask, false);
2566 }
2567
2568 if (newSelectedTask) {
2569 onSelect(newSelectedTask, true);
2570 }
2571 }
2572
2573 setSelectedTask(newSelectedTask);
2574 };
2575
2576 var handleExpanderClick = function handleExpanderClick(task) {
2577 if (onExpanderClick && task.hideChildren !== undefined) {
2578 onExpanderClick(_extends({}, task, {
2579 hideChildren: !task.hideChildren
2580 }));
2581 }
2582 };
2583
2584 var gridProps = {
2585 columnWidth: columnWidth,
2586 svgWidth: svgWidth,
2587 tasks: tasks,
2588 rowHeight: rowHeight,
2589 dates: dateSetup.dates,
2590 todayColor: todayColor,
2591 rtl: rtl
2592 };
2593 var calendarProps = {
2594 dateSetup: dateSetup,
2595 locale: locale,
2596 viewMode: viewMode,
2597 headerHeight: headerHeight,
2598 columnWidth: columnWidth,
2599 fontFamily: fontFamily,
2600 fontSize: fontSize,
2601 rtl: rtl
2602 };
2603 var barProps = {
2604 tasks: barTasks,
2605 dates: dateSetup.dates,
2606 ganttEvent: ganttEvent,
2607 selectedTask: selectedTask,
2608 rowHeight: rowHeight,
2609 taskHeight: taskHeight,
2610 columnWidth: columnWidth,
2611 arrowColor: arrowColor,
2612 timeStep: timeStep,
2613 fontFamily: fontFamily,
2614 fontSize: fontSize,
2615 arrowIndent: arrowIndent,
2616 svgWidth: svgWidth,
2617 rtl: rtl,
2618 setGanttEvent: setGanttEvent,
2619 setFailedTask: setFailedTask,
2620 setSelectedTask: handleSelectedTask,
2621 onDateChange: onDateChange,
2622 onProgressChange: onProgressChange,
2623 onDoubleClick: onDoubleClick,
2624 onClick: onClick,
2625 onDelete: onDelete
2626 };
2627 var tableProps = {
2628 rowHeight: rowHeight,
2629 rowWidth: listCellWidth,
2630 fontFamily: fontFamily,
2631 fontSize: fontSize,
2632 tasks: barTasks,
2633 locale: locale,
2634 headerHeight: headerHeight,
2635 scrollY: scrollY,
2636 ganttHeight: ganttHeight,
2637 horizontalContainerClass: styles$9.horizontalContainer,
2638 selectedTask: selectedTask,
2639 taskListRef: taskListRef,
2640 setSelectedTask: handleSelectedTask,
2641 onExpanderClick: handleExpanderClick,
2642 TaskListHeader: TaskListHeader,
2643 TaskListTable: TaskListTable
2644 };
2645 return React.createElement("div", null, React.createElement("div", {
2646 className: styles$9.wrapper,
2647 onKeyDown: handleKeyDown,
2648 tabIndex: 0,
2649 ref: wrapperRef
2650 }, listCellWidth && React.createElement(TaskList, Object.assign({}, tableProps)), React.createElement(TaskGantt, {
2651 gridProps: gridProps,
2652 calendarProps: calendarProps,
2653 barProps: barProps,
2654 ganttHeight: ganttHeight,
2655 scrollY: scrollY,
2656 scrollX: scrollX
2657 }), ganttEvent.changedTask && React.createElement(Tooltip, {
2658 arrowIndent: arrowIndent,
2659 rowHeight: rowHeight,
2660 svgContainerHeight: svgContainerHeight,
2661 svgContainerWidth: svgContainerWidth,
2662 fontFamily: fontFamily,
2663 fontSize: fontSize,
2664 scrollX: scrollX,
2665 scrollY: scrollY,
2666 task: ganttEvent.changedTask,
2667 headerHeight: headerHeight,
2668 taskListWidth: taskListWidth,
2669 TooltipContent: TooltipContent,
2670 rtl: rtl,
2671 svgWidth: svgWidth
2672 }), React.createElement(VerticalScroll, {
2673 ganttFullHeight: ganttFullHeight,
2674 ganttHeight: ganttHeight,
2675 headerHeight: headerHeight,
2676 scroll: scrollY,
2677 onScroll: handleScrollY,
2678 rtl: rtl
2679 })), React.createElement(HorizontalScroll, {
2680 svgWidth: svgWidth,
2681 taskListWidth: taskListWidth,
2682 scroll: scrollX,
2683 rtl: rtl,
2684 onScroll: handleScrollX
2685 }));
2686};
2687
2688export { Gantt, ViewMode };
2689//# sourceMappingURL=index.modern.js.map