@itcase/gantt-old 0.0.0-stage → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/README.md +0 -3
  2. package/dist/css/components/Chart/Chart.css +15 -0
  3. package/dist/css/components/Dependencies/Dependence.css +6 -0
  4. package/dist/css/components/Divider/Divider.css +94 -0
  5. package/dist/css/components/EmployeesList/EmployeesList.css +41 -0
  6. package/dist/css/components/GroupBar/GroupBar.css +20 -0
  7. package/dist/css/components/Header/Header.css +55 -0
  8. package/dist/css/components/InvalidTaskBar/InvalidTaskBar.css +23 -0
  9. package/dist/css/components/Scale/Scale.css +62 -0
  10. package/dist/css/components/ScrollBar/ScrollBar.css +16 -0
  11. package/dist/css/components/ScrollTop/ScrollTop.css +16 -0
  12. package/dist/css/components/SelectionIndicator/SelectionIndicator.css +7 -0
  13. package/dist/css/components/TableBody/RowToggler.css +25 -0
  14. package/dist/css/components/TableInterval/TableInterval.css +65 -0
  15. package/dist/css/components/TableTask/TableTask.css +41 -0
  16. package/dist/css/components/TaskBar/TaskBar.css +96 -0
  17. package/dist/css/components/TaskBarThumb/TaskBarThumb.css +35 -0
  18. package/dist/css/components/TimeIndicator/TimeIndicator.css +18 -0
  19. package/dist/css/components/Today/Today.css +13 -0
  20. package/dist/css/styles/main.css +758 -0
  21. package/dist/css/styles/mediaqueries.css +66 -0
  22. package/dist/css/styles/mixin_elevation.css +33 -0
  23. package/dist/css/styles/mixin_fill-gradient.css +23 -0
  24. package/dist/css/styles/mixin_global.css +54 -0
  25. package/dist/esm/index.js +3592 -0
  26. package/dist/types/components/BarList/BarList.d.ts +3 -0
  27. package/dist/types/components/BarList/index.d.ts +2 -0
  28. package/dist/types/components/BarThumbList/BarThumbList.d.ts +3 -0
  29. package/dist/types/components/BarThumbList/index.d.ts +2 -0
  30. package/dist/types/components/Chart/Chart.d.ts +3 -0
  31. package/dist/types/components/Chart/index.d.ts +2 -0
  32. package/dist/types/components/ContextMenu/index.d.ts +2 -0
  33. package/dist/types/components/Dependencies/Dependence.d.ts +7 -0
  34. package/dist/types/components/Dependencies/Dependencies.d.ts +3 -0
  35. package/dist/types/components/Dependencies/index.d.ts +2 -0
  36. package/dist/types/components/Divider/Divider.d.ts +3 -0
  37. package/dist/types/components/Divider/index.d.ts +2 -0
  38. package/dist/types/components/DragGroupOverlay/DragGroupOverlay.d.ts +6 -0
  39. package/dist/types/components/DragGroupOverlay/dragGroupOverlay.interface.d.ts +8 -0
  40. package/dist/types/components/DragGroupOverlay/index.d.ts +2 -0
  41. package/dist/types/components/DragPlaceOverlay/DragPlaceOverlay.d.ts +6 -0
  42. package/dist/types/components/DragPlaceOverlay/dragPlaceOverlay.interface.d.ts +6 -0
  43. package/dist/types/components/DragPlaceOverlay/index.d.ts +2 -0
  44. package/dist/types/components/DragPresent/DragPresent.d.ts +3 -0
  45. package/dist/types/components/DragPresent/index.d.ts +2 -0
  46. package/dist/types/components/DragResize/AutoScroller.d.ts +22 -0
  47. package/dist/types/components/DragResize/DragResize.d.ts +30 -0
  48. package/dist/types/components/DragResize/index.d.ts +2 -0
  49. package/dist/types/components/DragTaskOverlay/DragTaskOverlay.d.ts +6 -0
  50. package/dist/types/components/DragTaskOverlay/DragTaskOverlay.interface.d.ts +7 -0
  51. package/dist/types/components/DragTaskOverlay/index.d.ts +2 -0
  52. package/dist/types/components/Draggable/Draggable.d.ts +21 -0
  53. package/dist/types/components/Draggable/DraggableOverlay.d.ts +9 -0
  54. package/dist/types/components/Draggable/draggable-svg.d.ts +9 -0
  55. package/dist/types/components/Draggable/index.d.ts +3 -0
  56. package/dist/types/components/EmployeesList/EmployeesList.d.ts +6 -0
  57. package/dist/types/components/EmployeesList/EmployeesList.interface.d.ts +13 -0
  58. package/dist/types/components/EmployeesList/index.d.ts +2 -0
  59. package/dist/types/components/Gantt/Gantt.d.ts +59 -0
  60. package/dist/types/components/GroupBar/GroupBar.d.ts +7 -0
  61. package/dist/types/components/GroupBar/index.d.ts +2 -0
  62. package/dist/types/components/GroupContainer/GroupContainer.d.ts +14 -0
  63. package/dist/types/components/GroupContainer/index.d.ts +3 -0
  64. package/dist/types/components/Header/Header.d.ts +3 -0
  65. package/dist/types/components/Header/index.d.ts +2 -0
  66. package/dist/types/components/InvalidTaskBar/InvalidTaskBar.d.ts +7 -0
  67. package/dist/types/components/InvalidTaskBar/index.d.ts +2 -0
  68. package/dist/types/components/Item/Item.d.ts +37 -0
  69. package/dist/types/components/Item/components/Action/Action.d.ts +9 -0
  70. package/dist/types/components/Item/components/Action/index.d.ts +2 -0
  71. package/dist/types/components/Item/components/Handle/Handle.d.ts +3 -0
  72. package/dist/types/components/Item/components/Handle/index.d.ts +1 -0
  73. package/dist/types/components/Item/components/Remove/Remove.d.ts +2 -0
  74. package/dist/types/components/Item/components/Remove/index.d.ts +1 -0
  75. package/dist/types/components/Item/components/index.d.ts +3 -0
  76. package/dist/types/components/Item/index.d.ts +3 -0
  77. package/dist/types/components/MultipleContainers/MultipleContainers.d.ts +5 -0
  78. package/dist/types/components/MultipleContainers/index.d.ts +2 -0
  79. package/dist/types/components/MultipleContainers/multipleContainers.interface.d.ts +26 -0
  80. package/dist/types/components/MultipleContainers/multipleContainersKeyboardCoordinates.d.ts +2 -0
  81. package/dist/types/components/PlaceContainer/PlaceContainer.d.ts +15 -0
  82. package/dist/types/components/PlaceContainer/index.d.ts +3 -0
  83. package/dist/types/components/Scale/Scale.d.ts +6 -0
  84. package/dist/types/components/Scale/index.d.ts +2 -0
  85. package/dist/types/components/ScrollBar/ScrollBar.d.ts +3 -0
  86. package/dist/types/components/ScrollBar/index.d.ts +2 -0
  87. package/dist/types/components/ScrollTop/ScrollTop.d.ts +3 -0
  88. package/dist/types/components/ScrollTop/index.d.ts +2 -0
  89. package/dist/types/components/SelectionIndicator/SelectionIndicator.d.ts +3 -0
  90. package/dist/types/components/SelectionIndicator/index.d.ts +2 -0
  91. package/dist/types/components/SortableContainer/SortableContainer.d.ts +13 -0
  92. package/dist/types/components/SortableContainer/index.d.ts +2 -0
  93. package/dist/types/components/SortableItem/SortableItem.d.ts +3 -0
  94. package/dist/types/components/SortableItem/index.d.ts +2 -0
  95. package/dist/types/components/SortableItem/sortableItem.interface.d.ts +20 -0
  96. package/dist/types/components/SortablePlace/SortablePlace.d.ts +16 -0
  97. package/dist/types/components/SortablePlace/index.d.ts +2 -0
  98. package/dist/types/components/Table/Table.d.ts +5 -0
  99. package/dist/types/components/Table/index.d.ts +2 -0
  100. package/dist/types/components/TableBody/RowToggler.d.ts +9 -0
  101. package/dist/types/components/TableBody/TableBody.d.ts +3 -0
  102. package/dist/types/components/TableBody/index.d.ts +2 -0
  103. package/dist/types/components/TableInterval/TableInterval.d.ts +3 -0
  104. package/dist/types/components/TableInterval/index.d.ts +2 -0
  105. package/dist/types/components/TableTask/TableTask.d.ts +3 -0
  106. package/dist/types/components/TableTask/index.d.ts +2 -0
  107. package/dist/types/components/TaskBar/TaskBar.d.ts +7 -0
  108. package/dist/types/components/TaskBar/index.d.ts +2 -0
  109. package/dist/types/components/TaskBarThumb/TaskBarThumb.d.ts +7 -0
  110. package/dist/types/components/TaskBarThumb/index.d.ts +2 -0
  111. package/dist/types/components/TimeIndicator/TimeIndicator.d.ts +3 -0
  112. package/dist/types/components/TimeIndicator/index.d.ts +2 -0
  113. package/dist/types/components/Today/Today.d.ts +3 -0
  114. package/dist/types/components/Today/index.d.ts +2 -0
  115. package/dist/types/config/constants.d.ts +7 -0
  116. package/dist/types/context/GanttContext.d.ts +44 -0
  117. package/dist/types/hooks/useDragResize.d.ts +10 -0
  118. package/dist/types/index.d.ts +5 -0
  119. package/dist/types/locales/index.d.ts +1 -0
  120. package/dist/types/locales/ru-ru.d.ts +2 -0
  121. package/dist/types/locales/types.d.ts +31 -0
  122. package/dist/types/providers/TasksPropsProvider.d.ts +3 -0
  123. package/dist/types/store/GanttStore.d.ts +181 -0
  124. package/dist/types/types/types.d.ts +262 -0
  125. package/dist/types/utils/index.d.ts +12 -0
  126. package/package.json +106 -4
@@ -0,0 +1,3592 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import React, { createContext, useContext, useMemo, createRef, useState, useRef, useCallback, useEffect, memo, forwardRef, useImperativeHandle } from 'react';
3
+ import { useMemoizedFn, useClickAway, useSize } from 'ahooks';
4
+ import dayjs from 'dayjs';
5
+ import ru from 'dayjs/locale/ru';
6
+ import advancedFormat from 'dayjs/plugin/advancedFormat';
7
+ import isBetween from 'dayjs/plugin/isBetween';
8
+ import isLeapYear from 'dayjs/plugin/isLeapYear';
9
+ import quarterOfYear from 'dayjs/plugin/quarterOfYear';
10
+ import updateLocale from 'dayjs/plugin/updateLocale';
11
+ import weekday from 'dayjs/plugin/weekday';
12
+ import weekOfYear from 'dayjs/plugin/weekOfYear';
13
+ import debounce from 'lodash/debounce';
14
+ import find from 'lodash/find';
15
+ import sortBy from 'lodash/sortBy';
16
+ import throttle from 'lodash/throttle';
17
+ import { makeObservable, runInAction, toJS, observable, action, computed } from 'mobx';
18
+ import { observer } from 'mobx-react-lite';
19
+ import { createPortal } from 'react-dom';
20
+ import classNames from 'classnames';
21
+ import { useSortable, defaultAnimateLayoutChanges, arrayMove, SortableContext, verticalListSortingStrategy, horizontalListSortingStrategy } from '@dnd-kit/sortable';
22
+ import { defaultDropAnimationSideEffects, useSensors, useSensor, MouseSensor, TouchSensor, DndContext, MeasuringStrategy, DragOverlay } from '@dnd-kit/core';
23
+ import { CSS } from '@dnd-kit/utilities';
24
+
25
+ /******************************************************************************
26
+ Copyright (c) Microsoft Corporation.
27
+
28
+ Permission to use, copy, modify, and/or distribute this software for any
29
+ purpose with or without fee is hereby granted.
30
+
31
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
32
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
33
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
34
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
35
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
36
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
37
+ PERFORMANCE OF THIS SOFTWARE.
38
+ ***************************************************************************** */
39
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
40
+
41
+
42
+ var __assign = function() {
43
+ __assign = Object.assign || function __assign(t) {
44
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
45
+ s = arguments[i];
46
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
47
+ }
48
+ return t;
49
+ };
50
+ return __assign.apply(this, arguments);
51
+ };
52
+
53
+ function __rest(s, e) {
54
+ var t = {};
55
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
56
+ t[p] = s[p];
57
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
58
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
59
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
60
+ t[p[i]] = s[p[i]];
61
+ }
62
+ return t;
63
+ }
64
+
65
+ function __decorate(decorators, target, key, desc) {
66
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
67
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
68
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
69
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
70
+ }
71
+
72
+ function __awaiter(thisArg, _arguments, P, generator) {
73
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
74
+ return new (P || (P = Promise))(function (resolve, reject) {
75
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
76
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
77
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
78
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
79
+ });
80
+ }
81
+
82
+ function __generator(thisArg, body) {
83
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
84
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
85
+ function verb(n) { return function (v) { return step([n, v]); }; }
86
+ function step(op) {
87
+ if (f) throw new TypeError("Generator is already executing.");
88
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
89
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
90
+ if (y = 0, t) op = [op[0] & 2, t.value];
91
+ switch (op[0]) {
92
+ case 0: case 1: t = op; break;
93
+ case 4: _.label++; return { value: op[1], done: false };
94
+ case 5: _.label++; y = op[1]; op = [0]; continue;
95
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
96
+ default:
97
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
98
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
99
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
100
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
101
+ if (t[2]) _.ops.pop();
102
+ _.trys.pop(); continue;
103
+ }
104
+ op = body.call(thisArg, _);
105
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
106
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
107
+ }
108
+ }
109
+
110
+ function __spreadArray(to, from, pack) {
111
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
112
+ if (ar || !(i in from)) {
113
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
114
+ ar[i] = from[i];
115
+ }
116
+ }
117
+ return to.concat(ar || Array.prototype.slice.call(from));
118
+ }
119
+
120
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
121
+ var e = new Error(message);
122
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
123
+ };
124
+
125
+ var TasksPropsContext = createContext({});
126
+ function TasksPropsProvider(props) {
127
+ var children = props.children, tableBefore = props.tableBefore, onDeleteTask = props.onDeleteTask;
128
+ var contextValue = useMemo(function () { return ({ tableBefore: tableBefore, onDeleteTask: onDeleteTask }); }, [tableBefore, onDeleteTask]);
129
+ return jsx(TasksPropsContext.Provider, { value: contextValue, children: children });
130
+ }
131
+ var useTasksProps = function () { return useContext(TasksPropsContext); };
132
+
133
+ var ROW_HEIGHT = 40;
134
+ var HEADER_HEIGHT = 56;
135
+ var BAR_HEIGHT = 8;
136
+ var TOP_PADDING = 0;
137
+ var TABLE_INDENT = 30;
138
+ var ONE_MIN_MS$1 = 60 * 1000;
139
+
140
+ var context = createContext({});
141
+
142
+ var ruRU = Object.freeze({
143
+ today: 'Сегодня',
144
+ hour: 'Часы',
145
+ minute: 'Минуты',
146
+ day: 'День',
147
+ days: 'Дни',
148
+ week: 'Недели',
149
+ month: 'Месяцы',
150
+ quarter: 'Кварталы',
151
+ halfYear: 'Полугодия',
152
+ firstHalf: 'Первое полугодие',
153
+ secondHalf: 'Второе полугодие',
154
+ majorFormat: {
155
+ minute: 'HH, D, MMMM',
156
+ hour: 'D, MMMM, YYYY',
157
+ day: 'YYYY, MMMM',
158
+ week: 'YYYY, MMMM',
159
+ month: 'YYYY',
160
+ quarter: 'YYYY',
161
+ halfYear: 'YYYY',
162
+ },
163
+ minorFormat: {
164
+ minute: 'mm',
165
+ hour: 'HH',
166
+ day: 'D',
167
+ week: 'YYYY-w неделя',
168
+ month: 'YYYY-MMMM',
169
+ quarter: 'Q [Квартал]',
170
+ halfYear: 'YYYY-',
171
+ },
172
+ });
173
+
174
+ // eslint-disable-next-line @typescript-eslint/no-namespace
175
+ var Gantt;
176
+ (function (Gantt) {
177
+ (function (ESightValues) {
178
+ ESightValues[ESightValues["hour"] = 200] = "hour";
179
+ ESightValues[ESightValues["day"] = 2700] = "day";
180
+ ESightValues[ESightValues["week"] = 9200] = "week";
181
+ ESightValues[ESightValues["month"] = 41000] = "month";
182
+ ESightValues[ESightValues["quarter"] = 86400] = "quarter";
183
+ // halfYear = 115200,
184
+ })(Gantt.ESightValues || (Gantt.ESightValues = {}));
185
+ })(Gantt || (Gantt = {}));
186
+
187
+ var genKey = (function () {
188
+ var key = 0;
189
+ return function () {
190
+ return key++;
191
+ };
192
+ })();
193
+ function transverseData(data) {
194
+ if (data === void 0) { data = []; }
195
+ var result = [];
196
+ for (var _i = 0, data_1 = data; _i < data_1.length; _i++) {
197
+ var record = data_1[_i];
198
+ // const group = {
199
+ // ...record,
200
+ // key: genKey(),
201
+ // record: record,
202
+ // tasks: record.tasks,
203
+ // sort: record.sort,
204
+ // isCollapsed: record.isCollapsed || false,
205
+ // }
206
+ var place = __assign(__assign({}, record), { key: genKey(), record: record, tasks: record.tasks, sort: record.sort, isCollapsed: !!record.isCollapsed, groups: record.groups.map(function (group) {
207
+ return __assign(__assign({}, group), { record: group, tasks: group.tasks, sort: group.sort, isCollapsed: group.isCollapsed || false });
208
+ }) });
209
+ result.push(place);
210
+ }
211
+ return result;
212
+ }
213
+ function formatDays(number) {
214
+ if (!Number.isSafeInteger(number))
215
+ return '0 дней';
216
+ var lastDigit = number % 10;
217
+ var lastTwoDigits = number % 100;
218
+ // Check exceptions for numbers from 11 to 14
219
+ if (lastTwoDigits >= 11 && lastTwoDigits <= 14)
220
+ return "".concat(number, " \u0434\u043D\u0435\u0439");
221
+ else if (lastDigit === 1)
222
+ return "".concat(number, " \u0434\u0435\u043D\u044C");
223
+ else if (lastDigit >= 2 && lastDigit <= 4)
224
+ return "".concat(number, " \u0434\u043D\u044F");
225
+ else
226
+ return "".concat(number, " \u0434\u043D\u0435\u0439");
227
+ }
228
+ function formatHours(number) {
229
+ if (!Number.isSafeInteger(number))
230
+ return '0 часов';
231
+ var lastDigit = number % 10;
232
+ var lastTwoDigits = number % 100;
233
+ // Check exceptions for numbers from 11 to 14
234
+ if (lastTwoDigits >= 11 && lastTwoDigits <= 14)
235
+ return "".concat(number, " \u0447\u0430\u0441\u043E\u0432");
236
+ else if (lastDigit === 1)
237
+ return "".concat(number, " \u0447\u0430\u0441");
238
+ else if (lastDigit >= 2 && lastDigit <= 4)
239
+ return "".concat(number, " \u0447\u0430\u0441\u0430");
240
+ else
241
+ return "".concat(number, " \u0447\u0430\u0441\u043E\u0432");
242
+ }
243
+ function formatMinutes(number) {
244
+ if (!Number.isSafeInteger(number))
245
+ return '0 минут';
246
+ var lastDigit = number % 10;
247
+ var lastTwoDigits = number % 100;
248
+ // Check exceptions for numbers from 11 to 14
249
+ if (lastTwoDigits >= 11 && lastTwoDigits <= 14)
250
+ return "".concat(number, " \u043C\u0438\u043D\u0443\u0442");
251
+ else if (lastDigit === 1)
252
+ return "".concat(number, " \u043C\u0438\u043D\u0443\u0442\u0430");
253
+ else if (lastDigit >= 2 && lastDigit <= 4)
254
+ return "".concat(number, " \u043C\u0438\u043D\u0443\u0442\u044B");
255
+ else
256
+ return "".concat(number, " \u043C\u0438\u043D\u0443\u0442");
257
+ }
258
+
259
+ /* eslint-disable */
260
+ // @ts-nocheck
261
+ // dayjs configuration and extension
262
+ dayjs.locale(ru);
263
+ dayjs.extend(weekday);
264
+ dayjs.extend(weekOfYear);
265
+ dayjs.extend(quarterOfYear);
266
+ dayjs.extend(advancedFormat);
267
+ dayjs.extend(isBetween);
268
+ dayjs.extend(isLeapYear);
269
+ dayjs.extend(updateLocale);
270
+ var defaultLocale = __assign({}, ruRU);
271
+ var ONE_DAY_MS = 86400000;
272
+ var ONE_HOUR_MS = ONE_DAY_MS / 24;
273
+ var ONE_MIN_MS = ONE_HOUR_MS / 60;
274
+ // Day view, week view, month view, quarter view
275
+ var getViewTypeList = function (locale) {
276
+ return [
277
+ { type: 'hour', label: locale.hour, value: Gantt.ESightValues.hour },
278
+ { type: 'day', label: locale.days, value: Gantt.ESightValues.day },
279
+ { type: 'week', label: locale.week, value: Gantt.ESightValues.week },
280
+ { type: 'month', label: locale.month, value: Gantt.ESightValues.month },
281
+ ];
282
+ };
283
+ function isRestDay(date) {
284
+ var calc = [6];
285
+ return calc.includes(dayjs(date).weekday());
286
+ }
287
+ var GanttStore = /** @class */ (function () {
288
+ function GanttStore(_a) {
289
+ var rowHeight = _a.rowHeight, _b = _a.disabled, disabled = _b === void 0 ? false : _b, customSights = _a.customSights, taskStatusesChoices = _a.taskStatusesChoices;
290
+ var _this = this;
291
+ this.locale = __assign({}, defaultLocale);
292
+ this.data = [];
293
+ this.originData = [];
294
+ this.columns = [];
295
+ this.dependencies = [];
296
+ this.scrolling = false;
297
+ this.scrollTop = 0;
298
+ this.collapse = false;
299
+ this.showSelectionIndicator = false;
300
+ this.selectionIndicatorTop = 0;
301
+ this.dragging = null;
302
+ this.draggingType = null;
303
+ this.disabled = false;
304
+ this.minDateLimit = null;
305
+ this.maxDateLimit = null;
306
+ this.contextMenuData = {
307
+ item: null
308
+ };
309
+ this.viewTypeList = getViewTypeList(this.locale);
310
+ this.gestureKeyPress = false;
311
+ this.mainElementRef = createRef();
312
+ this.chartElementRef = createRef();
313
+ this.isPointerPress = false;
314
+ this.startDateKey = 'dt_begin';
315
+ this.endDateKey = 'dt_end';
316
+ this.autoScrollPos = 0;
317
+ this.clientX = 0;
318
+ this.taskStatusesChoices = {};
319
+ this.onUpdate = function () {
320
+ Promise.resolve(true);
321
+ };
322
+ this.onSortingChange = function (_updatedGroup) {
323
+ return Promise.resolve(true);
324
+ };
325
+ this.onGroupSortingChange = function (updatedGroupsList, placeId) {
326
+ return [updatedGroupsList, placeId];
327
+ };
328
+ this.onPlaceSortingChange = function (_updatedPlacesList) {
329
+ return;
330
+ };
331
+ this.onMoveTaskToAnotherGroup = function (_newGroup, _oldGroup, _movedTask) {
332
+ return Promise.resolve(true);
333
+ };
334
+ this.onCreateNewTask = function (_newTask, _groupId) {
335
+ return true;
336
+ };
337
+ this.onAddTaskAssignee = function (_taskId) {
338
+ return _taskId;
339
+ };
340
+ this.isRestDay = isRestDay;
341
+ this.getWidthByDate = function (dt_begin, dt_end) {
342
+ return (dt_end.valueOf() - dt_begin.valueOf()) / _this.pxUnitAmp;
343
+ };
344
+ this.startXRectBar = function (startX) {
345
+ var date = dayjs(startX * _this.pxUnitAmp);
346
+ var hourRect = function () {
347
+ var stAmp = date.startOf('hour').set('minute', 0).set('second', 0);
348
+ var endAmp = date.add(1, 'hour').set('minute', 0).set('second', 0);
349
+ // @ts-expect-error foo
350
+ var left = stAmp / _this.pxUnitAmp;
351
+ // @ts-expect-error foo
352
+ var width = (endAmp - stAmp) / _this.pxUnitAmp;
353
+ return {
354
+ left: left,
355
+ width: width,
356
+ };
357
+ };
358
+ var dayRect = function () {
359
+ var stAmp = date.startOf('day');
360
+ var endAmp = date.add(1, 'day').startOf('day');
361
+ // @ts-expect-error foo
362
+ var left = stAmp / _this.pxUnitAmp;
363
+ // @ts-expect-error foo
364
+ var width = (endAmp - stAmp) / _this.pxUnitAmp;
365
+ return {
366
+ left: left,
367
+ width: width,
368
+ };
369
+ };
370
+ var weekRect = function () {
371
+ if (date.weekday() === 0)
372
+ date = date.add(-1, 'week');
373
+ var left = date.weekday(1).startOf('day').valueOf() / _this.pxUnitAmp;
374
+ var width = (7 * 24 * 60 * 60 * 1000 - 1000) / _this.pxUnitAmp;
375
+ return {
376
+ left: left,
377
+ width: width,
378
+ };
379
+ };
380
+ var monthRect = function () {
381
+ var stAmp = date.startOf('month').valueOf();
382
+ var endAmp = date.endOf('month').valueOf();
383
+ var left = stAmp / _this.pxUnitAmp;
384
+ var width = (endAmp - stAmp) / _this.pxUnitAmp;
385
+ return {
386
+ left: left,
387
+ width: width,
388
+ };
389
+ };
390
+ var map = {
391
+ hour: hourRect,
392
+ day: dayRect,
393
+ week: weekRect,
394
+ month: weekRect,
395
+ quarter: monthRect,
396
+ };
397
+ return map[_this.sightConfig.type]();
398
+ };
399
+ this.handleWheel = function (event) {
400
+ if (event.deltaX !== 0) {
401
+ event.preventDefault();
402
+ event.stopPropagation();
403
+ }
404
+ if (_this._wheelTimer)
405
+ clearTimeout(_this._wheelTimer);
406
+ // Horizontal scrolling
407
+ if (Math.abs(event.deltaX) > 0) {
408
+ _this.setScrolling(true);
409
+ _this.setTranslateX(_this.translateX + event.deltaX);
410
+ }
411
+ _this._wheelTimer = window.setTimeout(function () {
412
+ _this.setScrolling(false);
413
+ }, 100);
414
+ };
415
+ this.handleScroll = function (event) {
416
+ var scrollTop = event.currentTarget.scrollTop;
417
+ _this.scrollY(scrollTop);
418
+ };
419
+ this.scrollY = throttle(function (scrollTop) {
420
+ _this.setScrollTop(scrollTop);
421
+ }, 100);
422
+ this.handleMouseMove = debounce(function (event) {
423
+ if (!_this.isPointerPress)
424
+ _this.showSelectionBar(event);
425
+ }, 5);
426
+ this.getHovered = function (top) {
427
+ var baseTop = top - (top % _this.rowHeight);
428
+ return (_this.selectionIndicatorTop >= baseTop &&
429
+ _this.selectionIndicatorTop <= baseTop + _this.rowHeight);
430
+ };
431
+ this.width = 1320;
432
+ this.height = 418;
433
+ this.viewTypeList = customSights.length ? customSights : getViewTypeList(defaultLocale);
434
+ var sightConfig = customSights.length ? customSights[0] : getViewTypeList(defaultLocale)[1];
435
+ var translateX = dayjs(this.getStartDate()).valueOf() / (sightConfig.value * 1000);
436
+ var bodyWidth = this.width;
437
+ var viewWidth = 704;
438
+ var tableWidth = 500;
439
+ this.viewWidth = viewWidth;
440
+ this.tableWidth = tableWidth;
441
+ this.translateX = translateX;
442
+ this.sightConfig = sightConfig;
443
+ this.bodyWidth = bodyWidth;
444
+ this.rowHeight = rowHeight;
445
+ this.disabled = disabled;
446
+ if (taskStatusesChoices) {
447
+ this.taskStatusesChoices = taskStatusesChoices;
448
+ }
449
+ makeObservable(this);
450
+ }
451
+ GanttStore.prototype.getStartDate = function () {
452
+ return dayjs().subtract(10, this.currentTimeUnit).toString();
453
+ };
454
+ GanttStore.prototype.setIsRestDay = function (function_) {
455
+ this.isRestDay = function_ || isRestDay;
456
+ };
457
+ GanttStore.prototype.update = function (data) {
458
+ var _this = this;
459
+ if (data === void 0) { data = {}; }
460
+ Object.entries(data).forEach(function (_a) {
461
+ var key = _a[0], value = _a[1];
462
+ _this[key] = value;
463
+ });
464
+ };
465
+ GanttStore.prototype.setData = function (data, startDateKey, endDateKey) {
466
+ var _this = this;
467
+ if (startDateKey === void 0) { startDateKey = 'dt_begin'; }
468
+ if (endDateKey === void 0) { endDateKey = 'dt_end'; }
469
+ this.startDateKey = startDateKey;
470
+ this.endDateKey = endDateKey;
471
+ this.originData = data;
472
+ this.data = transverseData(data.map(function (placeItem) {
473
+ var _a;
474
+ return (__assign(__assign({}, placeItem), { groups: placeItem.groups.map(function (groupItem) {
475
+ var _a;
476
+ return (__assign(__assign({}, groupItem), { isCollapsed: (_a = _this.getAllGroupRecordsList.find(function (group) { return String(group.id) === String(groupItem.id); })) === null || _a === void 0 ? void 0 : _a.isCollapsed }));
477
+ }), isCollapsed: (_a = _this.data.find(function (groupItem) { return String(groupItem.record.id) === String(placeItem.id); })) === null || _a === void 0 ? void 0 : _a.isCollapsed }));
478
+ }));
479
+ };
480
+ GanttStore.prototype.setShowSelectionIndicator = function (showSelectionIndicator) {
481
+ this.showSelectionIndicator = showSelectionIndicator;
482
+ };
483
+ GanttStore.prototype.setScrollTop = function (scrollTopValue) {
484
+ this.scrollTop = scrollTopValue;
485
+ };
486
+ GanttStore.prototype.setScrolling = function (scrolling) {
487
+ this.scrolling = scrolling;
488
+ };
489
+ GanttStore.prototype.toggleCollapse = function () {
490
+ if (this.tableWidth > 0) {
491
+ this.tableWidth = 0;
492
+ this.viewWidth = this.width - this.tableWidth;
493
+ }
494
+ else {
495
+ this.initWidth();
496
+ }
497
+ };
498
+ GanttStore.prototype.toggleCollapseGroup = function (groupId) {
499
+ var group = this.getAllGroupRecordsList.find(function (group) { return String(group.id) === String(groupId); });
500
+ if (!group) {
501
+ return;
502
+ }
503
+ group.isCollapsed = !group.isCollapsed;
504
+ };
505
+ GanttStore.prototype.toggleCollapsePlace = function (placeId) {
506
+ var placeIndex = this.data.findIndex(function (place) { return String(place.id) === String(placeId); });
507
+ if (placeIndex === -1) {
508
+ return;
509
+ }
510
+ this.data[placeIndex].isCollapsed = !this.data[placeIndex].isCollapsed;
511
+ };
512
+ GanttStore.prototype.setRowCollapse = function (item, isCollapsed) {
513
+ item.isCollapsed = isCollapsed;
514
+ };
515
+ GanttStore.prototype.setOnUpdate = function (onUpdate) {
516
+ this.onUpdate = onUpdate;
517
+ };
518
+ GanttStore.prototype.setOnSortingChange = function (onSortingChange) {
519
+ this.onSortingChange = onSortingChange;
520
+ };
521
+ GanttStore.prototype.setOnGroupSortingChange = function (onGroupSortingChange) {
522
+ this.onGroupSortingChange = onGroupSortingChange;
523
+ };
524
+ GanttStore.prototype.setOnPlaceSortingChange = function (onPlaceSortingChange) {
525
+ this.onPlaceSortingChange = onPlaceSortingChange;
526
+ };
527
+ GanttStore.prototype.setOnMoveTaskToAnotherGroup = function (onMoveTaskToAnotherGroup) {
528
+ this.onMoveTaskToAnotherGroup = onMoveTaskToAnotherGroup;
529
+ };
530
+ GanttStore.prototype.setOnCreateNewTask = function (onCreateNewTask) {
531
+ this.onCreateNewTask = onCreateNewTask;
532
+ };
533
+ GanttStore.prototype.setOnAddTaskAssignee = function (onAddTaskAssignee) {
534
+ this.onAddTaskAssignee = onAddTaskAssignee;
535
+ };
536
+ GanttStore.prototype.setColumns = function (columns) {
537
+ this.columns = columns;
538
+ };
539
+ GanttStore.prototype.setDependencies = function (dependencies) {
540
+ this.dependencies = dependencies;
541
+ };
542
+ GanttStore.prototype.setHideTable = function (isHidden) {
543
+ if (isHidden === void 0) { isHidden = false; }
544
+ if (isHidden) {
545
+ this.tableWidth = 0;
546
+ this.viewWidth = this.width - this.tableWidth;
547
+ }
548
+ else {
549
+ this.initWidth();
550
+ }
551
+ };
552
+ GanttStore.prototype.setMinDateLimit = function (minDateLimit) {
553
+ if (!minDateLimit)
554
+ return;
555
+ this.minDateLimit = dayjs(minDateLimit).startOf(this.currentTimeUnit).valueOf();
556
+ };
557
+ GanttStore.prototype.setMaxDateLimit = function (maxDateLimit) {
558
+ if (!maxDateLimit)
559
+ return;
560
+ this.maxDateLimit = dayjs(maxDateLimit).startOf(this.currentTimeUnit).valueOf();
561
+ };
562
+ GanttStore.prototype.handlePanMove = function (translateX) {
563
+ this.setScrolling(true);
564
+ this.setTranslateX(translateX);
565
+ };
566
+ GanttStore.prototype.handlePanEnd = function () {
567
+ this.setScrolling(false);
568
+ };
569
+ GanttStore.prototype.syncSize = function (size) {
570
+ if ((size === null || size === void 0 ? void 0 : size.height) && (this === null || this === void 0 ? void 0 : this.height) !== (size === null || size === void 0 ? void 0 : size.height))
571
+ this.height = size === null || size === void 0 ? void 0 : size.height;
572
+ if ((size === null || size === void 0 ? void 0 : size.width) && this.width !== size.width) {
573
+ this.width = size.width;
574
+ this.initWidth();
575
+ }
576
+ };
577
+ GanttStore.prototype.handleResizeTableWidth = function (width) {
578
+ // const columnsWidthArr = this.columns.filter((column) => column.width > 0)
579
+ // if (this.columns.length === columnsWidthArr.length) return
580
+ this.tableWidth = width;
581
+ this.viewWidth = this.width - this.tableWidth;
582
+ };
583
+ GanttStore.prototype.initWidth = function () {
584
+ this.tableWidth = 800;
585
+ this.viewWidth = this.width - this.tableWidth;
586
+ // Chart width cannot be less than 200
587
+ if (this.viewWidth < 200) {
588
+ this.viewWidth = 200;
589
+ this.tableWidth = this.width - this.viewWidth;
590
+ }
591
+ };
592
+ GanttStore.prototype.setTranslateX = function (translateX) {
593
+ if (this.translateX) {
594
+ this.translateX = Math.max(translateX, 0);
595
+ }
596
+ };
597
+ GanttStore.prototype.switchSight = function (type) {
598
+ var target = find(this.viewTypeList, { type: type });
599
+ if (target) {
600
+ this.sightConfig = target;
601
+ this.setTranslateX(dayjs(this.getStartDate()).valueOf() / (target.value * 1000));
602
+ }
603
+ };
604
+ GanttStore.prototype.scrollToToday = function () {
605
+ var translateX = this.todayTranslateX - this.viewWidth / 2;
606
+ this.setTranslateX(translateX);
607
+ };
608
+ GanttStore.prototype.getTranslateXByDate = function (date) {
609
+ return dayjs(date).startOf(this.currentTimeUnit).valueOf() / this.pxUnitAmp;
610
+ };
611
+ Object.defineProperty(GanttStore.prototype, "currentTimeUnit", {
612
+ get: function () {
613
+ return 'minute'; // minute is atomic & the only one supported time unit
614
+ },
615
+ enumerable: false,
616
+ configurable: true
617
+ });
618
+ Object.defineProperty(GanttStore.prototype, "todayTranslateX", {
619
+ get: function () {
620
+ return dayjs().startOf(this.sightConfig.type).valueOf() / this.pxUnitAmp;
621
+ },
622
+ enumerable: false,
623
+ configurable: true
624
+ });
625
+ Object.defineProperty(GanttStore.prototype, "scrollBarWidth", {
626
+ get: function () {
627
+ var MIN_WIDTH = 100;
628
+ return Math.max((this.viewWidth / this.scrollWidth) * 175, MIN_WIDTH);
629
+ },
630
+ enumerable: false,
631
+ configurable: true
632
+ });
633
+ Object.defineProperty(GanttStore.prototype, "scrollBalanceRatio", {
634
+ get: function () {
635
+ return this.scrollWidth <= 10000 ? 0.25 : 0.25;
636
+ },
637
+ enumerable: false,
638
+ configurable: true
639
+ });
640
+ Object.defineProperty(GanttStore.prototype, "scrollLimitations", {
641
+ get: function () {
642
+ var _a, _b;
643
+ var leftLimit = this.minDateLimit
644
+ ? this.getTranslateXByDate(dayjs(this.minDateLimit).format('YYYY-MM-DD'))
645
+ : Math.min.apply(Math, (_a = this.getBarList) === null || _a === void 0 ? void 0 : _a.map(function (bar) { return (bar === null || bar === void 0 ? void 0 : bar.translateX) - (bar === null || bar === void 0 ? void 0 : bar.width); })) - 5000;
646
+ var rightLimit = this.maxDateLimit
647
+ ? this.getTranslateXByDate(dayjs(this.maxDateLimit).format('YYYY-MM-DD'))
648
+ : Math.max.apply(Math, (_b = this.getBarList) === null || _b === void 0 ? void 0 : _b.map(function (bar) { return (bar === null || bar === void 0 ? void 0 : bar.translateX) + (bar === null || bar === void 0 ? void 0 : bar.width); })) + 5000;
649
+ return { min: leftLimit, max: rightLimit };
650
+ },
651
+ enumerable: false,
652
+ configurable: true
653
+ });
654
+ Object.defineProperty(GanttStore.prototype, "scrollLeft", {
655
+ get: function () {
656
+ var rate = (this.viewWidth / this.scrollWidth) * this.scrollBalanceRatio; // this.scrollBalanceRatio < 1 for scrollbar speed reducion
657
+ var currentDate = dayjs(this.translateAmp).toString();
658
+ var half = (this.viewWidth - this.scrollBarWidth) / 2;
659
+ var viewScrollLeft = half +
660
+ rate * (this.getTranslateXByDate(currentDate) - this.getTranslateXByDate(this.getStartDate()));
661
+ return Math.min(Math.max(viewScrollLeft, 0), this.viewWidth - this.scrollBarWidth * 0.2);
662
+ },
663
+ enumerable: false,
664
+ configurable: true
665
+ });
666
+ Object.defineProperty(GanttStore.prototype, "scrollWidth", {
667
+ get: function () {
668
+ // TODO to be studied
669
+ // minimum width
670
+ var init = this.viewWidth + 200;
671
+ return Math.max(Math.abs(this.viewWidth + this.translateX - this.getTranslateXByDate(this.getStartDate())), init);
672
+ },
673
+ enumerable: false,
674
+ configurable: true
675
+ });
676
+ Object.defineProperty(GanttStore.prototype, "bodyClientHeight", {
677
+ // Content area scroll height
678
+ get: function () {
679
+ // 1 is the border
680
+ return this.height - HEADER_HEIGHT - 1;
681
+ },
682
+ enumerable: false,
683
+ configurable: true
684
+ });
685
+ GanttStore.prototype.getMaxRange = function (bar) {
686
+ var _a, _b, _c, _d, _e;
687
+ var tasks = (_a = bar === null || bar === void 0 ? void 0 : bar.record) === null || _a === void 0 ? void 0 : _a.tasks;
688
+ if (tasks) {
689
+ var earliestDate_1 = dayjs((_c = (_b = tasks[0]) === null || _b === void 0 ? void 0 : _b.task) === null || _c === void 0 ? void 0 : _c.dt_begin);
690
+ var latestDate_1 = dayjs((_e = (_d = tasks[0]) === null || _d === void 0 ? void 0 : _d.task) === null || _e === void 0 ? void 0 : _e.dt_end);
691
+ if (!earliestDate_1 || !latestDate_1)
692
+ return { width: 0, translateX: 0 };
693
+ // Iterate through each task to determine the earliest start date and latest end date
694
+ tasks.forEach(function (taskRecord) {
695
+ var _a, _b;
696
+ var beginDate = dayjs((_a = taskRecord === null || taskRecord === void 0 ? void 0 : taskRecord.task) === null || _a === void 0 ? void 0 : _a.dt_begin);
697
+ var endDate = dayjs((_b = taskRecord === null || taskRecord === void 0 ? void 0 : taskRecord.task) === null || _b === void 0 ? void 0 : _b.dt_end);
698
+ if (beginDate && beginDate.isBefore(earliestDate_1)) {
699
+ earliestDate_1 = beginDate;
700
+ }
701
+ if (endDate && endDate.isAfter(latestDate_1)) {
702
+ latestDate_1 = endDate;
703
+ }
704
+ });
705
+ var valid = (earliestDate_1 === null || earliestDate_1 === void 0 ? void 0 : earliestDate_1.toISOString()) && (latestDate_1 === null || latestDate_1 === void 0 ? void 0 : latestDate_1.toISOString());
706
+ var startAmp = dayjs(earliestDate_1.toISOString() || 0)
707
+ .startOf(this.currentTimeUnit)
708
+ .valueOf();
709
+ var endAmp = dayjs(latestDate_1.toISOString() || 0)
710
+ .endOf(this.currentTimeUnit)
711
+ .valueOf();
712
+ var width = valid ? (endAmp - startAmp) / this.pxUnitAmp : 0;
713
+ var translateX = valid ? startAmp / this.pxUnitAmp : 0;
714
+ return {
715
+ width: width,
716
+ translateX: translateX,
717
+ earliestDate: earliestDate_1,
718
+ latestDate: latestDate_1,
719
+ };
720
+ }
721
+ return { width: 0, translateX: 0 };
722
+ };
723
+ Object.defineProperty(GanttStore.prototype, "bodyScrollHeight", {
724
+ // body scroll area height
725
+ get: function () {
726
+ var height = this.getBarList.length * this.rowHeight + TOP_PADDING;
727
+ if (height < this.bodyClientHeight)
728
+ height = this.bodyClientHeight;
729
+ return height;
730
+ },
731
+ enumerable: false,
732
+ configurable: true
733
+ });
734
+ Object.defineProperty(GanttStore.prototype, "pxUnitAmp", {
735
+ // The number of milliseconds corresponding to 1px
736
+ get: function () {
737
+ return this.sightConfig.value * 1000;
738
+ },
739
+ enumerable: false,
740
+ configurable: true
741
+ });
742
+ Object.defineProperty(GanttStore.prototype, "translateAmp", {
743
+ /** Current start time in milliseconds */
744
+ get: function () {
745
+ var translateX = this.translateX;
746
+ return this.pxUnitAmp * translateX;
747
+ },
748
+ enumerable: false,
749
+ configurable: true
750
+ });
751
+ GanttStore.prototype.getDurationAmp = function () {
752
+ var clientWidth = this.viewWidth;
753
+ return this.pxUnitAmp * clientWidth;
754
+ };
755
+ GanttStore.prototype.getMajorList = function () {
756
+ var majorFormatMap = {
757
+ hour: this.locale.majorFormat.hour,
758
+ day: this.locale.majorFormat.day,
759
+ week: this.locale.majorFormat.week,
760
+ month: this.locale.majorFormat.month,
761
+ quarter: this.locale.majorFormat.quarter,
762
+ };
763
+ var translateAmp = this.translateAmp;
764
+ var endAmp = translateAmp + this.getDurationAmp();
765
+ var type = this.sightConfig.type;
766
+ var format = majorFormatMap[type];
767
+ var getNextDate = function (start) {
768
+ if (type === 'hour' || type === 'day' || type === 'week')
769
+ return start.add(1, 'month');
770
+ return start.add(1, 'year');
771
+ };
772
+ var getStart = function (date) {
773
+ if (type === 'hour' || type === 'day' || type === 'week')
774
+ return date.startOf('month');
775
+ return date.startOf('year');
776
+ };
777
+ var getEnd = function (date) {
778
+ if (type === 'hour' || type === 'day' || type === 'week')
779
+ return date.endOf('month');
780
+ return date.endOf('year');
781
+ };
782
+ // Initialize the current time
783
+ var currentDate = dayjs(translateAmp);
784
+ var dates = [];
785
+ // Iterate over time within the visible area
786
+ while (currentDate.isBetween(translateAmp - 1, endAmp + 1)) {
787
+ var majorKey = currentDate.format(format);
788
+ var start = currentDate;
789
+ var end = getEnd(start);
790
+ if (dates.length > 0)
791
+ start = getStart(currentDate);
792
+ dates.push({
793
+ label: majorKey,
794
+ dt_begin: start,
795
+ dt_end: end,
796
+ });
797
+ // Get the time of the next iteration
798
+ start = getStart(currentDate);
799
+ currentDate = getNextDate(start);
800
+ }
801
+ return this.majorAmp2Px(dates);
802
+ };
803
+ GanttStore.prototype.majorAmp2Px = function (ampList) {
804
+ var pxUnitAmp = this.pxUnitAmp;
805
+ return ampList.map(function (item) {
806
+ var dt_begin = item.dt_begin;
807
+ var dt_end = item.dt_end;
808
+ var label = item.label;
809
+ var left = dt_begin.valueOf() / pxUnitAmp;
810
+ var width = (dt_end.valueOf() - dt_begin.valueOf()) / pxUnitAmp;
811
+ return {
812
+ label: label,
813
+ left: left,
814
+ width: width,
815
+ key: dt_begin.format('YYYY-MM-DD HH:mm:ss'),
816
+ };
817
+ });
818
+ };
819
+ GanttStore.prototype.getMinorList = function () {
820
+ var _this = this;
821
+ var minorFormatMap = {
822
+ minute: this.locale.minorFormat.minute,
823
+ hour: this.locale.minorFormat.hour,
824
+ day: this.locale.minorFormat.day,
825
+ week: this.locale.minorFormat.week,
826
+ month: this.locale.minorFormat.month,
827
+ quarter: this.locale.minorFormat.quarter,
828
+ halfYear: this.locale.minorFormat.halfYear,
829
+ };
830
+ var fstHalfYear = new Set([0, 1, 2, 3, 4, 5]);
831
+ var startAmp = this.translateAmp;
832
+ var endAmp = startAmp + this.getDurationAmp();
833
+ var format = minorFormatMap[this.sightConfig.type];
834
+ var getNextDate = function (start) {
835
+ var map = {
836
+ minute: function () { return start.add(30, 'minute'); },
837
+ hour: function () { return start.add(1, 'hour'); },
838
+ day: function () { return start.add(1, 'day'); },
839
+ week: function () { return start.add(1, 'week'); },
840
+ month: function () { return start.add(1, 'month'); },
841
+ quarter: function () { return start.add(1, 'quarter'); },
842
+ halfYear: function () { return start.add(6, 'month'); },
843
+ };
844
+ return map[_this.sightConfig.type]();
845
+ };
846
+ var setStart = function (date) {
847
+ var map = {
848
+ minute: function () { return date.startOf('hour'); },
849
+ hour: function () { return date.startOf('hour'); },
850
+ day: function () { return date.startOf('day'); },
851
+ week: function () { return date.weekday(1).hour(0).minute(0).second(0); },
852
+ month: function () { return date.startOf('month'); },
853
+ quarter: function () { return date.startOf('quarter'); },
854
+ halfYear: function () {
855
+ return fstHalfYear.has(date.month())
856
+ ? date.month(0).startOf('month')
857
+ : date.month(6).startOf('month');
858
+ },
859
+ };
860
+ return map[_this.sightConfig.type]();
861
+ };
862
+ var setEnd = function (start) {
863
+ var map = {
864
+ minute: function () { return start.endOf('hour'); },
865
+ hour: function () { return start.endOf('hour'); },
866
+ day: function () { return start.endOf('day'); },
867
+ week: function () { return start.weekday(7).hour(23).minute(59).second(59); },
868
+ month: function () { return start.endOf('month'); },
869
+ quarter: function () { return start.endOf('quarter'); },
870
+ halfYear: function () {
871
+ return fstHalfYear.has(start.month())
872
+ ? start.month(5).endOf('month')
873
+ : start.month(11).endOf('month');
874
+ },
875
+ };
876
+ return map[_this.sightConfig.type]();
877
+ };
878
+ var getMinorKey = function (date) {
879
+ return date.format(format);
880
+ };
881
+ // Initialize the current time
882
+ var currentDate = dayjs(startAmp);
883
+ var dates = [];
884
+ while (currentDate.isBetween(startAmp - 1, endAmp + 1)) {
885
+ var minorKey = getMinorKey(currentDate);
886
+ var start = setStart(currentDate);
887
+ var end = setEnd(start);
888
+ dates.push({
889
+ label: minorKey.split('-').pop(),
890
+ dt_begin: start,
891
+ dt_end: end,
892
+ });
893
+ currentDate = getNextDate(start);
894
+ }
895
+ return this.minorAmp2Px(dates);
896
+ };
897
+ GanttStore.prototype.minorAmp2Px = function (ampList) {
898
+ var _this = this;
899
+ var pxUnitAmp = this.pxUnitAmp;
900
+ return ampList.map(function (item) {
901
+ var dt_begin = item.dt_begin;
902
+ var dt_end = item.dt_end;
903
+ var label = item.label;
904
+ var left = dt_begin.valueOf() / pxUnitAmp;
905
+ var width = (dt_end.valueOf() - dt_begin.valueOf()) / pxUnitAmp;
906
+ var isWeek = false;
907
+ if (_this.sightConfig.type === 'day')
908
+ isWeek = _this.isRestDay(dt_begin.toString());
909
+ return {
910
+ label: label,
911
+ left: left,
912
+ width: width,
913
+ isWeek: isWeek,
914
+ key: dt_begin.format('YYYY-MM-DD HH:mm:ss'),
915
+ };
916
+ });
917
+ };
918
+ GanttStore.prototype.getTaskBarThumbVisible = function (barInfo) {
919
+ var width = barInfo.width, barTranslateX = barInfo.translateX, invalidDateRange = barInfo.invalidDateRange;
920
+ if (invalidDateRange)
921
+ return false;
922
+ var rightSide = this.translateX + this.viewWidth;
923
+ return barTranslateX + width < this.translateX || barTranslateX - rightSide > 0;
924
+ };
925
+ GanttStore.prototype.scrollToBar = function (barInfo, type) {
926
+ var barTranslateX = barInfo.translateX, width = barInfo.width;
927
+ var translateX1 = this.translateX + this.viewWidth / 2;
928
+ var translateX2 = barTranslateX + width;
929
+ var diffX = Math.abs(translateX2 - translateX1);
930
+ var translateX = this.translateX + diffX;
931
+ if (type === 'left')
932
+ translateX = this.translateX - diffX;
933
+ this.setTranslateX(translateX);
934
+ };
935
+ Object.defineProperty(GanttStore.prototype, "getColumnsWidth", {
936
+ get: function () {
937
+ var _a;
938
+ if (this.columns.length === 1 && ((_a = this.columns[0]) === null || _a === void 0 ? void 0 : _a.width) < 200) {
939
+ return [200];
940
+ }
941
+ var totalColumnWidth = this.columns.reduce(function (width, item) { return width + (item.width || 0); }, 0);
942
+ var totalFlex = this.columns.reduce(function (total, item) { return total + (item.width ? 0 : item.flex || 1); }, 0);
943
+ var restWidth = this.tableWidth - totalColumnWidth;
944
+ return this.columns.map(function (column) {
945
+ if (column.width) {
946
+ return column.width;
947
+ }
948
+ if (column.flex) {
949
+ return restWidth * (column.flex / totalFlex);
950
+ }
951
+ return restWidth * (1 / totalFlex);
952
+ });
953
+ },
954
+ enumerable: false,
955
+ configurable: true
956
+ });
957
+ Object.defineProperty(GanttStore.prototype, "getAllGroupRecordsList", {
958
+ get: function () {
959
+ var recordsList = this.data
960
+ .map(function (place) {
961
+ return __assign({}, place.groups);
962
+ })
963
+ .map(function (groups) {
964
+ return Object.values(groups);
965
+ })
966
+ .flat(2);
967
+ return recordsList;
968
+ },
969
+ enumerable: false,
970
+ configurable: true
971
+ });
972
+ Object.defineProperty(GanttStore.prototype, "getRecordList", {
973
+ get: function () {
974
+ return this.data.map(function (place) {
975
+ return __assign(__assign({}, place.record), { isCollapsed: !!place.isCollapsed, groups: place.groups.map(function (group) {
976
+ return __assign(__assign({}, group.record), { isCollapsed: group.isCollapsed });
977
+ }) });
978
+ });
979
+ },
980
+ enumerable: false,
981
+ configurable: true
982
+ });
983
+ Object.defineProperty(GanttStore.prototype, "getBarList", {
984
+ get: function () {
985
+ var _this = this;
986
+ var _a = this, pxUnitAmp = _a.pxUnitAmp, data = _a.data;
987
+ var height = 8;
988
+ var baseTop = TOP_PADDING + this.rowHeight / 2 - height / 2;
989
+ var topStep = this.rowHeight;
990
+ var dateTextFormat = function (startX) {
991
+ return dayjs(startX * pxUnitAmp).format('DD-MM-YYYY HH:mm');
992
+ };
993
+ var getDateWidth = function (start, endX, timeUnit) {
994
+ if (timeUnit === void 0) { timeUnit = _this.currentTimeUnit; }
995
+ var dt_begin = dayjs(Math.floor(start) * pxUnitAmp);
996
+ var dt_end = dayjs(Math.floor(endX) * pxUnitAmp);
997
+ return "".concat(dt_begin.diff(dt_end, timeUnit));
998
+ };
999
+ var getBar = function (item, index, groupId) {
1000
+ var _a, _b, _c, _d, _e, _f;
1001
+ var valid = ((_a = item === null || item === void 0 ? void 0 : item.task) === null || _a === void 0 ? void 0 : _a.dt_begin) && ((_b = item === null || item === void 0 ? void 0 : item.task) === null || _b === void 0 ? void 0 : _b.dt_end);
1002
+ var startAmp = dayjs(((_c = item === null || item === void 0 ? void 0 : item.task) === null || _c === void 0 ? void 0 : _c.dt_begin) || 0)
1003
+ .startOf(_this.currentTimeUnit)
1004
+ .valueOf();
1005
+ var endAmp = dayjs(((_d = item === null || item === void 0 ? void 0 : item.task) === null || _d === void 0 ? void 0 : _d.dt_end) || 0)
1006
+ .endOf(_this.currentTimeUnit)
1007
+ .valueOf();
1008
+ var width = valid ? (endAmp - startAmp) / pxUnitAmp : 0;
1009
+ var translateX = valid ? startAmp / pxUnitAmp : 0;
1010
+ var translateY = baseTop + index * topStep;
1011
+ var _parent = item._parent;
1012
+ var record = __assign(__assign({}, item), { disabled: _this.disabled });
1013
+ if (item === 'add_task') {
1014
+ return {
1015
+ isGroupRow: false,
1016
+ isPlaceRow: false,
1017
+ groupId: groupId,
1018
+ key: item.key + 500,
1019
+ task: { dt_begin: '', dt_end: '' },
1020
+ record: { disabled: _this.disabled },
1021
+ translateX: translateX,
1022
+ translateY: translateY,
1023
+ width: width,
1024
+ label: item.content,
1025
+ stepGesture: 'end',
1026
+ invalidDateRange: !((_e = item === null || item === void 0 ? void 0 : item.task) === null || _e === void 0 ? void 0 : _e.dt_end) || !((_f = item === null || item === void 0 ? void 0 : item.task) === null || _f === void 0 ? void 0 : _f.dt_begin),
1027
+ dateTextFormat: dateTextFormat,
1028
+ getDateWidth: getDateWidth,
1029
+ loading: false,
1030
+ _group: item.group,
1031
+ _depth: item._depth,
1032
+ _index: item._index,
1033
+ _parent: _parent,
1034
+ _childrenCount: !item.children ? 0 : item.children.length,
1035
+ };
1036
+ }
1037
+ if (item.task) {
1038
+ // regular task case
1039
+ return {
1040
+ isGroupRow: false,
1041
+ isPlaceRow: false,
1042
+ key: item.key,
1043
+ task: item.task,
1044
+ record: record,
1045
+ translateX: translateX,
1046
+ translateY: translateY,
1047
+ width: width,
1048
+ label: item.content,
1049
+ stepGesture: 'end',
1050
+ invalidDateRange: false,
1051
+ dateTextFormat: dateTextFormat,
1052
+ getDateWidth: getDateWidth,
1053
+ loading: false,
1054
+ _group: item.group,
1055
+ _depth: item._depth,
1056
+ _index: item._index,
1057
+ _parent: _parent,
1058
+ _childrenCount: !item.children ? 0 : item.children.length,
1059
+ };
1060
+ }
1061
+ else if (item.tasks) {
1062
+ // group row case
1063
+ return {
1064
+ isGroupRow: true,
1065
+ isPlaceRow: false,
1066
+ key: item.key,
1067
+ task: null,
1068
+ record: record,
1069
+ translateX: translateX,
1070
+ translateY: translateY,
1071
+ width: width,
1072
+ label: item.content,
1073
+ stepGesture: 'end',
1074
+ invalidDateRange: false,
1075
+ dateTextFormat: dateTextFormat,
1076
+ getDateWidth: getDateWidth,
1077
+ loading: false,
1078
+ _group: item.group,
1079
+ _depth: item._depth,
1080
+ _index: item._index,
1081
+ _parent: _parent,
1082
+ _childrenCount: !item.children ? 0 : item.children.length,
1083
+ };
1084
+ }
1085
+ else {
1086
+ // place row case
1087
+ return {
1088
+ isGroupRow: false,
1089
+ isPlaceRow: true,
1090
+ key: item.key,
1091
+ task: null,
1092
+ record: record,
1093
+ translateX: translateX,
1094
+ translateY: translateY,
1095
+ width: width,
1096
+ label: item.content,
1097
+ stepGesture: 'end',
1098
+ invalidDateRange: false,
1099
+ dateTextFormat: dateTextFormat,
1100
+ getDateWidth: getDateWidth,
1101
+ loading: false,
1102
+ _group: item.group,
1103
+ _depth: item._depth,
1104
+ _index: item._index,
1105
+ _parent: _parent,
1106
+ _childrenCount: !item.children ? 0 : item.children.length,
1107
+ };
1108
+ }
1109
+ };
1110
+ var barList = [];
1111
+ var index = 0;
1112
+ // TODO: move sort to "setData" function. Also see "src/components/Table/Table.tsx"
1113
+ var sortedPlacesList = sortBy(data, 'sort');
1114
+ for (var _i = 0, sortedPlacesList_1 = sortedPlacesList; _i < sortedPlacesList_1.length; _i++) {
1115
+ var placeItem = sortedPlacesList_1[_i];
1116
+ barList.push(getBar(placeItem, index++));
1117
+ if (!placeItem.isCollapsed) {
1118
+ var sortedGroupsList = sortBy(placeItem.groups, 'sort');
1119
+ for (var _b = 0, sortedGroupsList_1 = sortedGroupsList; _b < sortedGroupsList_1.length; _b++) {
1120
+ var groupItem = sortedGroupsList_1[_b];
1121
+ barList.push(getBar(groupItem, index++));
1122
+ if (!groupItem.isCollapsed) {
1123
+ var sortedTasksList = sortBy(groupItem.tasks, 'sort');
1124
+ for (var _c = 0, sortedTasksList_1 = sortedTasksList; _c < sortedTasksList_1.length; _c++) {
1125
+ var task = sortedTasksList_1[_c];
1126
+ barList.push(getBar(task, index++));
1127
+ }
1128
+ barList.push(getBar('add_task', index++, groupItem.id));
1129
+ }
1130
+ }
1131
+ }
1132
+ }
1133
+ return barList;
1134
+ },
1135
+ enumerable: false,
1136
+ configurable: true
1137
+ });
1138
+ Object.defineProperty(GanttStore.prototype, "getVisibleRows", {
1139
+ // virtual scrolling
1140
+ get: function () {
1141
+ var visibleHeight = this.bodyClientHeight;
1142
+ // Render more and reduce the blank space
1143
+ var visibleRowCount = Math.ceil(visibleHeight / this.rowHeight) + 10;
1144
+ var start = Math.max(Math.ceil(this.scrollTop / this.rowHeight) - 5, 0);
1145
+ return {
1146
+ start: start,
1147
+ count: visibleRowCount,
1148
+ };
1149
+ },
1150
+ enumerable: false,
1151
+ configurable: true
1152
+ });
1153
+ GanttStore.prototype.handleMouseLeave = function () {
1154
+ this.setShowSelectionIndicator(false);
1155
+ };
1156
+ GanttStore.prototype.showSelectionBar = function (event) {
1157
+ var _a, _b;
1158
+ var scrollTop = ((_a = this.mainElementRef.current) === null || _a === void 0 ? void 0 : _a.scrollTop) || 0;
1159
+ var top = (((_b = this.mainElementRef.current) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect()) || {
1160
+ top: 0,
1161
+ }).top;
1162
+ // content area height
1163
+ var contentHeight = this.getBarList.length * this.rowHeight;
1164
+ var offsetY = event.clientY - top + scrollTop;
1165
+ if (offsetY - contentHeight > TOP_PADDING) {
1166
+ this.setShowSelectionIndicator(false);
1167
+ }
1168
+ else {
1169
+ var topValue = Math.floor((offsetY - TOP_PADDING) / this.rowHeight) * this.rowHeight + TOP_PADDING;
1170
+ this.setShowSelectionIndicator(true);
1171
+ this.selectionIndicatorTop = topValue;
1172
+ }
1173
+ };
1174
+ GanttStore.prototype.handleDragStart = function (barInfo, type) {
1175
+ this.dragging = barInfo;
1176
+ this.draggingType = type;
1177
+ barInfo.stepGesture = 'start';
1178
+ this.isPointerPress = true;
1179
+ };
1180
+ GanttStore.prototype.handleDragEnd = function () {
1181
+ if (this.dragging) {
1182
+ this.dragging.stepGesture = 'end';
1183
+ this.dragging = null;
1184
+ }
1185
+ this.draggingType = null;
1186
+ this.isPointerPress = false;
1187
+ };
1188
+ GanttStore.prototype.handleInvalidBarLeave = function () {
1189
+ this.handleDragEnd();
1190
+ };
1191
+ GanttStore.prototype.handleInvalidBarHover = function (barInfo, left, width) {
1192
+ barInfo.translateX = left;
1193
+ barInfo.width = width;
1194
+ this.handleDragStart(barInfo, 'create');
1195
+ };
1196
+ GanttStore.prototype.handleInvalidBarDragStart = function (barInfo) {
1197
+ barInfo.stepGesture = 'moving';
1198
+ };
1199
+ GanttStore.prototype.handleInvalidBarDragEnd = function (barInfo, oldSize) {
1200
+ return __awaiter(this, void 0, void 0, function () {
1201
+ var newTaskPlaceIndex, newTaskPlace, newTaskGroup, newTaskPlaceKey, newTaskPlaceId, newTaskSort, newTaskDtBegin, newTaskDtEnd, newTaskDataObject, isNewTaskCreated;
1202
+ var _a;
1203
+ var _b, _c, _d;
1204
+ return __generator(this, function (_e) {
1205
+ switch (_e.label) {
1206
+ case 0:
1207
+ barInfo.invalidDateRange = false;
1208
+ this.handleDragEnd();
1209
+ newTaskPlaceIndex = this.data.findIndex(function (place) {
1210
+ return ((place === null || place === void 0 ? void 0 : place.groups.length) > 0 && (place === null || place === void 0 ? void 0 : place.groups.map(function (group) { return group.id; }).includes(barInfo.groupId)));
1211
+ });
1212
+ newTaskPlace = this.data[newTaskPlaceIndex];
1213
+ newTaskGroup = (_b = this.data[newTaskPlaceIndex]) === null || _b === void 0 ? void 0 : _b.groups.find(function (group) { return String(group.id) === String(barInfo.groupId); });
1214
+ newTaskPlaceKey = (newTaskPlace === null || newTaskPlace === void 0 ? void 0 : newTaskPlace.placeKey) || '';
1215
+ newTaskPlaceId = (_c = newTaskPlace[newTaskPlaceKey]) === null || _c === void 0 ? void 0 : _c.id;
1216
+ newTaskSort = Math.max.apply(Math, __spreadArray(__spreadArray([], newTaskGroup.tasks.map(function (taskRecord) { return taskRecord.sort; }), false), [0], false)) + 1;
1217
+ newTaskDtBegin = dayjs(barInfo.translateX * this.pxUnitAmp).format('YYYY-MM-DD HH:mm');
1218
+ newTaskDtEnd = dayjs((barInfo.translateX + barInfo.width) * this.pxUnitAmp).format('YYYY-MM-DD HH:mm');
1219
+ if (!((newTaskPlace === null || newTaskPlace === void 0 ? void 0 : newTaskPlace.placeKey) && newTaskGroup && newTaskPlaceKey && newTaskPlaceId))
1220
+ return [2 /*return*/];
1221
+ newTaskDataObject = (_a = {
1222
+ name: 'Новая задача',
1223
+ sort: newTaskSort,
1224
+ name_short: 'Новая задача'
1225
+ },
1226
+ _a[newTaskPlace === null || newTaskPlace === void 0 ? void 0 : newTaskPlace.placeKey] = (_d = newTaskPlace[newTaskPlace === null || newTaskPlace === void 0 ? void 0 : newTaskPlace.placeKey]) === null || _d === void 0 ? void 0 : _d.id,
1227
+ _a.group = barInfo.groupId,
1228
+ _a.dt_begin = newTaskDtBegin,
1229
+ _a.dt_end = newTaskDtEnd,
1230
+ _a);
1231
+ return [4 /*yield*/, this.createNewTask(newTaskDataObject, newTaskGroup.id)];
1232
+ case 1:
1233
+ isNewTaskCreated = _e.sent();
1234
+ if (isNewTaskCreated === false) {
1235
+ barInfo.width = oldSize.width;
1236
+ barInfo.translateX = oldSize.x;
1237
+ barInfo.invalidDateRange = true;
1238
+ barInfo.stepGesture = 'start';
1239
+ }
1240
+ return [2 /*return*/];
1241
+ }
1242
+ });
1243
+ });
1244
+ };
1245
+ GanttStore.prototype.updateBarSize = function (barInfo, _a) {
1246
+ var width = _a.width, x = _a.x;
1247
+ barInfo.width = width;
1248
+ barInfo.translateX = Math.max(x, 0);
1249
+ barInfo.stepGesture = 'moving';
1250
+ if (!this.dragging)
1251
+ return barInfo;
1252
+ this.dragging.width = width;
1253
+ this.dragging.translateX = Math.max(x, 0);
1254
+ return barInfo;
1255
+ };
1256
+ GanttStore.prototype.getMovedDay = function (ms) {
1257
+ if (this.sightConfig.type === 'hour')
1258
+ return Math.round(ms / ONE_HOUR_MS);
1259
+ return Math.round(ms / ONE_DAY_MS);
1260
+ };
1261
+ GanttStore.prototype.getMovedHour = function (ms) {
1262
+ return Math.round(ms / ONE_HOUR_MS);
1263
+ };
1264
+ GanttStore.prototype.getMovedMinutes = function (ms) {
1265
+ return Math.round(ms / ONE_MIN_MS);
1266
+ };
1267
+ GanttStore.prototype.updateTaskMinutes = function (barInfo, oldSize, type) {
1268
+ return __awaiter(this, void 0, void 0, function () {
1269
+ var translateX, width, record, oldStartDate, oldEndDate, dt_begin, dt_end, moveMinutes, moveMinutes, moveMinutes, success;
1270
+ return __generator(this, function (_a) {
1271
+ switch (_a.label) {
1272
+ case 0:
1273
+ translateX = barInfo.translateX, width = barInfo.width, record = barInfo.record;
1274
+ oldStartDate = barInfo.task.dt_begin;
1275
+ oldEndDate = barInfo.task.dt_end;
1276
+ dt_begin = dayjs(oldStartDate) // .format('YYYY-MM-DD HH:mm')
1277
+ ;
1278
+ dt_end = dayjs(oldEndDate) // .format('YYYY-MM-DD HH:mm')
1279
+ ;
1280
+ if (type === 'move') {
1281
+ moveMinutes = this.getMovedMinutes((translateX - oldSize.x) * this.pxUnitAmp);
1282
+ dt_begin = dayjs(oldStartDate).add(moveMinutes, 'minutes'); // .format('YYYY-MM-DD HH:mm')
1283
+ dt_end = dayjs(oldEndDate).add(moveMinutes, 'minutes'); // .format('YYYY-MM-DD HH:mm')
1284
+ }
1285
+ else if (type === 'left') {
1286
+ moveMinutes = this.getMovedMinutes((translateX - oldSize.x) * this.pxUnitAmp);
1287
+ dt_begin = dayjs(oldStartDate).add(moveMinutes, 'minutes'); // .format('YYYY-MM-DD HH:mm')
1288
+ }
1289
+ else if (type === 'right') {
1290
+ moveMinutes = this.getMovedMinutes((width - oldSize.width) * this.pxUnitAmp);
1291
+ dt_end = dayjs(oldEndDate).add(moveMinutes, 'minutes'); // .format('YYYY-MM-DD HH:mm')
1292
+ }
1293
+ if (dt_begin === oldStartDate && dt_end === oldEndDate)
1294
+ return [2 /*return*/];
1295
+ runInAction(function () {
1296
+ barInfo.loading = true;
1297
+ });
1298
+ return [4 /*yield*/, this.onUpdate(toJS(record), dt_begin, dt_end)];
1299
+ case 1:
1300
+ success = _a.sent();
1301
+ if (!success) {
1302
+ barInfo.width = oldSize.width;
1303
+ barInfo.translateX = oldSize.x;
1304
+ }
1305
+ return [2 /*return*/];
1306
+ }
1307
+ });
1308
+ });
1309
+ };
1310
+ GanttStore.prototype.updateOriginGroupsSorting = function (updatedGroupsList, placeId) {
1311
+ this.onGroupSortingChange(updatedGroupsList, placeId);
1312
+ };
1313
+ GanttStore.prototype.createNewTask = function (newTask, groupId) {
1314
+ return this.onCreateNewTask(newTask, groupId);
1315
+ };
1316
+ GanttStore.prototype.isToday = function (key) {
1317
+ var now = dayjs().format('YYYY-MM-DD');
1318
+ var target = dayjs(key).format('YYYY-MM-DD');
1319
+ return target === now;
1320
+ };
1321
+ GanttStore.prototype.isCurrentHour = function (key) {
1322
+ var now = dayjs().format('YYYY-MM-DD HH');
1323
+ var target = dayjs(key).format('YYYY-MM-DD HH');
1324
+ return target === now;
1325
+ };
1326
+ __decorate([
1327
+ observable
1328
+ ], GanttStore.prototype, "locale", void 0);
1329
+ __decorate([
1330
+ observable
1331
+ ], GanttStore.prototype, "data", void 0);
1332
+ __decorate([
1333
+ observable
1334
+ ], GanttStore.prototype, "originData", void 0);
1335
+ __decorate([
1336
+ observable
1337
+ ], GanttStore.prototype, "columns", void 0);
1338
+ __decorate([
1339
+ observable
1340
+ ], GanttStore.prototype, "dependencies", void 0);
1341
+ __decorate([
1342
+ observable
1343
+ ], GanttStore.prototype, "scrolling", void 0);
1344
+ __decorate([
1345
+ observable
1346
+ ], GanttStore.prototype, "scrollTop", void 0);
1347
+ __decorate([
1348
+ observable
1349
+ ], GanttStore.prototype, "collapse", void 0);
1350
+ __decorate([
1351
+ observable
1352
+ ], GanttStore.prototype, "tableWidth", void 0);
1353
+ __decorate([
1354
+ observable
1355
+ ], GanttStore.prototype, "viewWidth", void 0);
1356
+ __decorate([
1357
+ observable
1358
+ ], GanttStore.prototype, "width", void 0);
1359
+ __decorate([
1360
+ observable
1361
+ ], GanttStore.prototype, "height", void 0);
1362
+ __decorate([
1363
+ observable
1364
+ ], GanttStore.prototype, "bodyWidth", void 0);
1365
+ __decorate([
1366
+ observable
1367
+ ], GanttStore.prototype, "translateX", void 0);
1368
+ __decorate([
1369
+ observable
1370
+ ], GanttStore.prototype, "sightConfig", void 0);
1371
+ __decorate([
1372
+ observable
1373
+ ], GanttStore.prototype, "showSelectionIndicator", void 0);
1374
+ __decorate([
1375
+ observable
1376
+ ], GanttStore.prototype, "selectionIndicatorTop", void 0);
1377
+ __decorate([
1378
+ observable
1379
+ ], GanttStore.prototype, "dragging", void 0);
1380
+ __decorate([
1381
+ observable
1382
+ ], GanttStore.prototype, "draggingType", void 0);
1383
+ __decorate([
1384
+ observable
1385
+ ], GanttStore.prototype, "disabled", void 0);
1386
+ __decorate([
1387
+ observable
1388
+ ], GanttStore.prototype, "minDateLimit", void 0);
1389
+ __decorate([
1390
+ observable
1391
+ ], GanttStore.prototype, "maxDateLimit", void 0);
1392
+ __decorate([
1393
+ observable
1394
+ ], GanttStore.prototype, "contextMenuData", void 0);
1395
+ __decorate([
1396
+ action
1397
+ ], GanttStore.prototype, "update", null);
1398
+ __decorate([
1399
+ action
1400
+ ], GanttStore.prototype, "setData", null);
1401
+ __decorate([
1402
+ action
1403
+ ], GanttStore.prototype, "setShowSelectionIndicator", null);
1404
+ __decorate([
1405
+ action
1406
+ ], GanttStore.prototype, "setScrollTop", null);
1407
+ __decorate([
1408
+ action
1409
+ ], GanttStore.prototype, "setScrolling", null);
1410
+ __decorate([
1411
+ action
1412
+ ], GanttStore.prototype, "toggleCollapse", null);
1413
+ __decorate([
1414
+ action
1415
+ ], GanttStore.prototype, "toggleCollapseGroup", null);
1416
+ __decorate([
1417
+ action
1418
+ ], GanttStore.prototype, "toggleCollapsePlace", null);
1419
+ __decorate([
1420
+ action
1421
+ ], GanttStore.prototype, "setRowCollapse", null);
1422
+ __decorate([
1423
+ action
1424
+ ], GanttStore.prototype, "setOnUpdate", null);
1425
+ __decorate([
1426
+ action
1427
+ ], GanttStore.prototype, "setOnSortingChange", null);
1428
+ __decorate([
1429
+ action
1430
+ ], GanttStore.prototype, "setOnGroupSortingChange", null);
1431
+ __decorate([
1432
+ action
1433
+ ], GanttStore.prototype, "setOnPlaceSortingChange", null);
1434
+ __decorate([
1435
+ action
1436
+ ], GanttStore.prototype, "setOnMoveTaskToAnotherGroup", null);
1437
+ __decorate([
1438
+ action
1439
+ ], GanttStore.prototype, "setOnCreateNewTask", null);
1440
+ __decorate([
1441
+ action
1442
+ ], GanttStore.prototype, "setOnAddTaskAssignee", null);
1443
+ __decorate([
1444
+ action
1445
+ ], GanttStore.prototype, "setColumns", null);
1446
+ __decorate([
1447
+ action
1448
+ ], GanttStore.prototype, "setDependencies", null);
1449
+ __decorate([
1450
+ action
1451
+ ], GanttStore.prototype, "setHideTable", null);
1452
+ __decorate([
1453
+ action
1454
+ ], GanttStore.prototype, "setMinDateLimit", null);
1455
+ __decorate([
1456
+ action
1457
+ ], GanttStore.prototype, "setMaxDateLimit", null);
1458
+ __decorate([
1459
+ action
1460
+ ], GanttStore.prototype, "handlePanMove", null);
1461
+ __decorate([
1462
+ action
1463
+ ], GanttStore.prototype, "handlePanEnd", null);
1464
+ __decorate([
1465
+ action
1466
+ ], GanttStore.prototype, "syncSize", null);
1467
+ __decorate([
1468
+ action
1469
+ ], GanttStore.prototype, "handleResizeTableWidth", null);
1470
+ __decorate([
1471
+ action
1472
+ ], GanttStore.prototype, "initWidth", null);
1473
+ __decorate([
1474
+ action
1475
+ ], GanttStore.prototype, "setTranslateX", null);
1476
+ __decorate([
1477
+ action
1478
+ ], GanttStore.prototype, "switchSight", null);
1479
+ __decorate([
1480
+ action
1481
+ ], GanttStore.prototype, "scrollToToday", null);
1482
+ __decorate([
1483
+ computed
1484
+ ], GanttStore.prototype, "currentTimeUnit", null);
1485
+ __decorate([
1486
+ computed
1487
+ ], GanttStore.prototype, "todayTranslateX", null);
1488
+ __decorate([
1489
+ computed
1490
+ ], GanttStore.prototype, "scrollBarWidth", null);
1491
+ __decorate([
1492
+ computed
1493
+ ], GanttStore.prototype, "scrollBalanceRatio", null);
1494
+ __decorate([
1495
+ computed
1496
+ ], GanttStore.prototype, "scrollLimitations", null);
1497
+ __decorate([
1498
+ computed
1499
+ ], GanttStore.prototype, "scrollLeft", null);
1500
+ __decorate([
1501
+ computed
1502
+ ], GanttStore.prototype, "scrollWidth", null);
1503
+ __decorate([
1504
+ computed
1505
+ ], GanttStore.prototype, "bodyClientHeight", null);
1506
+ __decorate([
1507
+ computed
1508
+ ], GanttStore.prototype, "bodyScrollHeight", null);
1509
+ __decorate([
1510
+ computed
1511
+ ], GanttStore.prototype, "pxUnitAmp", null);
1512
+ __decorate([
1513
+ computed
1514
+ ], GanttStore.prototype, "translateAmp", null);
1515
+ __decorate([
1516
+ computed
1517
+ ], GanttStore.prototype, "getColumnsWidth", null);
1518
+ __decorate([
1519
+ computed
1520
+ ], GanttStore.prototype, "getAllGroupRecordsList", null);
1521
+ __decorate([
1522
+ computed
1523
+ ], GanttStore.prototype, "getRecordList", null);
1524
+ __decorate([
1525
+ computed
1526
+ ], GanttStore.prototype, "getBarList", null);
1527
+ __decorate([
1528
+ action
1529
+ ], GanttStore.prototype, "handleWheel", void 0);
1530
+ __decorate([
1531
+ computed
1532
+ ], GanttStore.prototype, "getVisibleRows", null);
1533
+ __decorate([
1534
+ action
1535
+ ], GanttStore.prototype, "showSelectionBar", null);
1536
+ __decorate([
1537
+ action
1538
+ ], GanttStore.prototype, "handleDragStart", null);
1539
+ __decorate([
1540
+ action
1541
+ ], GanttStore.prototype, "handleDragEnd", null);
1542
+ __decorate([
1543
+ action
1544
+ ], GanttStore.prototype, "handleInvalidBarLeave", null);
1545
+ __decorate([
1546
+ action
1547
+ ], GanttStore.prototype, "handleInvalidBarHover", null);
1548
+ __decorate([
1549
+ action
1550
+ ], GanttStore.prototype, "handleInvalidBarDragStart", null);
1551
+ __decorate([
1552
+ action
1553
+ ], GanttStore.prototype, "handleInvalidBarDragEnd", null);
1554
+ __decorate([
1555
+ action
1556
+ ], GanttStore.prototype, "updateBarSize", null);
1557
+ __decorate([
1558
+ action
1559
+ ], GanttStore.prototype, "updateTaskMinutes", null);
1560
+ __decorate([
1561
+ action
1562
+ ], GanttStore.prototype, "updateOriginGroupsSorting", null);
1563
+ __decorate([
1564
+ action
1565
+ ], GanttStore.prototype, "createNewTask", null);
1566
+ return GanttStore;
1567
+ }());
1568
+
1569
+ var height = 8;
1570
+ var GroupBar = function (_a) {
1571
+ var data = _a.data;
1572
+ var _b = useContext(context), renderGroupBar = _b.renderGroupBar, store = _b.store;
1573
+ var translateY = data.translateY;
1574
+ var _c = store.getMaxRange(data), translateX = _c.translateX, width = _c.width, earliestDate = _c.earliestDate, latestDate = _c.latestDate;
1575
+ return (jsx("div", { className: "gantt__groupbar", role: "none", style: {
1576
+ transform: "translate(".concat(translateX, "px, ").concat(translateY, "px)"),
1577
+ }, children: jsx("div", { className: "gantt__groupbar-item", children: renderGroupBar ? (renderGroupBar(data, {
1578
+ width: width,
1579
+ height: height,
1580
+ })) : (jsxs(React.Fragment, { children: [jsxs("span", { className: "gantt__groupbar-item-text", children: [earliestDate.format('DD.MM.YYYY'), " - ", latestDate.format('DD.MM.YYYY')] }), jsxs("svg", { width: width, height: height + 6, viewBox: "0 0 ".concat(width, " ").concat(height + 6), fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsx("rect", { width: width, height: "6", fill: "#9747FF" }), jsx("path", { d: "M0 6H8L4 10L0 14V6Z", fill: "#9747FF" }), jsx("path", { d: "M".concat(width, " 6H").concat(width - 8, "L").concat(width - 4, " 10L").concat(width, " 14V6Z"), fill: "#9747FF" })] })] })) }) }));
1581
+ };
1582
+ var GroupBar$1 = observer(GroupBar);
1583
+
1584
+ var AutoScroller = /** @class */ (function () {
1585
+ function AutoScroller(_a) {
1586
+ var scroller = _a.scroller, _b = _a.rate, rate = _b === void 0 ? 5 : _b, _c = _a.space, space = _c === void 0 ? 50 : _c, onAutoScroll = _a.onAutoScroll, reachEdge = _a.reachEdge;
1587
+ var _this = this;
1588
+ this.scroller = null;
1589
+ this.autoScrollPos = 0;
1590
+ this.clientX = null;
1591
+ this.scrollTimer = null;
1592
+ this.handleDraggingMouseMove = function (event) {
1593
+ _this.clientX = event.clientX;
1594
+ };
1595
+ this.handleScroll = function (position) {
1596
+ if (_this.reachEdge(position))
1597
+ return;
1598
+ if (position === 'left') {
1599
+ _this.autoScrollPos -= _this.rate;
1600
+ _this.onAutoScroll(-_this.rate);
1601
+ }
1602
+ else if (position === 'right') {
1603
+ _this.autoScrollPos += _this.rate;
1604
+ _this.onAutoScroll(_this.rate);
1605
+ }
1606
+ };
1607
+ this.start = function () {
1608
+ _this.autoScrollPos = 0;
1609
+ document.addEventListener('mousemove', _this.handleDraggingMouseMove);
1610
+ var scrollFunc = function () {
1611
+ var _a, _b;
1612
+ if (_this.scroller && _this.clientX !== null) {
1613
+ if (_this.clientX + _this.space > ((_a = _this.scroller) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().right))
1614
+ _this.handleScroll('right');
1615
+ else if (_this.clientX - _this.space < ((_b = _this.scroller) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect().left))
1616
+ _this.handleScroll('left');
1617
+ }
1618
+ _this.scrollTimer = requestAnimationFrame(scrollFunc);
1619
+ };
1620
+ _this.scrollTimer = requestAnimationFrame(scrollFunc);
1621
+ };
1622
+ // Stop automatic scrolling
1623
+ this.stop = function () {
1624
+ document.removeEventListener('mousemove', _this.handleDraggingMouseMove);
1625
+ if (_this.scrollTimer)
1626
+ cancelAnimationFrame(_this.scrollTimer);
1627
+ };
1628
+ this.scroller = scroller || null;
1629
+ this.rate = rate;
1630
+ this.space = space;
1631
+ this.onAutoScroll = onAutoScroll;
1632
+ this.reachEdge = reachEdge;
1633
+ }
1634
+ return AutoScroller;
1635
+ }());
1636
+
1637
+ var snap = function (n, size) { return Math.round(n / size) * size; };
1638
+ var DragResize = function (_a) {
1639
+ var children = _a.children, _b = _a.minWidth, minWidth = _b === void 0 ? 0 : _b, _c = _a.autoScroll, enableAutoScroll = _c === void 0 ? true : _c, _d = _a.clickStart, clickStart = _d === void 0 ? false : _d, _e = _a.defaultSize, defaultWidth = _e.width, defaultX = _e.x, _f = _a.disabled, disabled = _f === void 0 ? false : _f, grid = _a.grid, _g = _a.reachEdge, reachEdge = _g === void 0 ? function () { return false; } : _g, scroller = _a.scroller, type = _a.type, onAutoScroll = _a.onAutoScroll, onBeforeResize = _a.onBeforeResize, onResize = _a.onResize, onResizeEnd = _a.onResizeEnd, otherProps = __rest(_a, ["children", "minWidth", "autoScroll", "clickStart", "defaultSize", "disabled", "grid", "reachEdge", "scroller", "type", "onAutoScroll", "onBeforeResize", "onResize", "onResizeEnd"]);
1640
+ var _h = useState(false), resizing = _h[0], setResizing = _h[1];
1641
+ var handleAutoScroll = useMemoizedFn(function (delta) {
1642
+ updateSize();
1643
+ onAutoScroll(delta);
1644
+ });
1645
+ // TODO persist reachEdge
1646
+ var autoScroll = useMemo(function () {
1647
+ return new AutoScroller({
1648
+ reachEdge: reachEdge,
1649
+ scroller: scroller,
1650
+ onAutoScroll: handleAutoScroll,
1651
+ });
1652
+ }, [handleAutoScroll, scroller, reachEdge]);
1653
+ var positionRef = useRef({
1654
+ width: defaultWidth,
1655
+ clientX: 0,
1656
+ x: defaultX,
1657
+ });
1658
+ var moveRef = useRef({
1659
+ clientX: 0,
1660
+ });
1661
+ var updateSize = useMemoizedFn(function () {
1662
+ if (disabled) {
1663
+ return;
1664
+ }
1665
+ var distance = moveRef.current.clientX - positionRef.current.clientX + autoScroll.autoScrollPos;
1666
+ switch (type) {
1667
+ case 'left': {
1668
+ var width = positionRef.current.width - distance;
1669
+ if (minWidth !== undefined)
1670
+ width = Math.max(width, minWidth);
1671
+ if (grid)
1672
+ width = snap(width, grid);
1673
+ var pos = width - positionRef.current.width;
1674
+ var x = positionRef.current.x - pos;
1675
+ onResize({ width: width, x: x });
1676
+ break;
1677
+ }
1678
+ // To the right, x remains unchanged, only the width changes
1679
+ case 'right': {
1680
+ var width = positionRef.current.width + distance;
1681
+ if (minWidth !== undefined)
1682
+ width = Math.max(width, minWidth);
1683
+ if (grid)
1684
+ width = snap(width, grid);
1685
+ var x = positionRef.current.x;
1686
+ onResize({ width: width, x: x });
1687
+ break;
1688
+ }
1689
+ case 'move': {
1690
+ var width = positionRef.current.width;
1691
+ var rightDistance = distance;
1692
+ if (grid)
1693
+ rightDistance = snap(distance, grid);
1694
+ var x = positionRef.current.x + rightDistance;
1695
+ onResize({ width: width, x: x });
1696
+ break;
1697
+ }
1698
+ }
1699
+ });
1700
+ var handleMouseMove = useMemoizedFn(function (event) {
1701
+ if (disabled) {
1702
+ return;
1703
+ }
1704
+ if (!resizing) {
1705
+ setResizing(true);
1706
+ if (!clickStart)
1707
+ onBeforeResize && onBeforeResize();
1708
+ }
1709
+ moveRef.current.clientX = event.clientX;
1710
+ updateSize();
1711
+ });
1712
+ var handleMouseUp = useMemoizedFn(function () {
1713
+ if (disabled) {
1714
+ return;
1715
+ }
1716
+ autoScroll.stop();
1717
+ window.removeEventListener('mousemove', handleMouseMove);
1718
+ window.removeEventListener('mouseup', handleMouseUp);
1719
+ if (resizing) {
1720
+ setResizing(false);
1721
+ onResizeEnd &&
1722
+ onResizeEnd({
1723
+ width: positionRef.current.width,
1724
+ x: positionRef.current.x,
1725
+ });
1726
+ }
1727
+ });
1728
+ var handleMouseDown = useMemoizedFn(function (event) {
1729
+ if (disabled) {
1730
+ return;
1731
+ }
1732
+ event.stopPropagation();
1733
+ if (enableAutoScroll && scroller)
1734
+ autoScroll.start();
1735
+ if (clickStart) {
1736
+ onBeforeResize && onBeforeResize();
1737
+ setResizing(true);
1738
+ }
1739
+ positionRef.current.clientX = event.clientX;
1740
+ positionRef.current.x = defaultX;
1741
+ positionRef.current.width = defaultWidth;
1742
+ window.addEventListener('mousemove', handleMouseMove);
1743
+ window.addEventListener('mouseup', handleMouseUp);
1744
+ });
1745
+ return (jsxs("div", __assign({ role: "none", onMouseDown: handleMouseDown }, otherProps, { children: [resizing &&
1746
+ createPortal(jsx("div", { style: {
1747
+ position: 'fixed',
1748
+ top: 0,
1749
+ right: 0,
1750
+ bottom: 0,
1751
+ left: 0,
1752
+ zIndex: 9999,
1753
+ cursor: disabled ? 'not-allowed' : 'col-resize',
1754
+ } }), document.body), children] })));
1755
+ };
1756
+ var DragResize$1 = observer(DragResize);
1757
+
1758
+ var barH = 8;
1759
+ var startX = 0;
1760
+ var renderInvalidBarDefault = function (element) { return element; };
1761
+ var InvalidTaskBar = function (_a) {
1762
+ var data = _a.data;
1763
+ var translateY = data.translateY, dateTextFormat = data.dateTextFormat, record = data.record;
1764
+ var _b = useContext(context), store = _b.store, _c = _b.renderInvalidBar, renderInvalidBar = _c === void 0 ? renderInvalidBarDefault : _c;
1765
+ var triggerRef = useRef(null);
1766
+ var _d = useState(false), visible = _d[0], setVisible = _d[1];
1767
+ var _e = useState(store.translateX), storeTranslateX = _e[0], setStoreTranslateX = _e[1];
1768
+ var _f = useState(data.translateX), dataTranslateX = _f[0], setDataTranslateX = _f[1];
1769
+ var _g = useState(store.width), dataWidth = _g[0], setDataWidth = _g[1];
1770
+ var _h = (record || {}).disabled, disabled = _h === void 0 ? false : _h;
1771
+ var rowHeight = store.rowHeight;
1772
+ var top = translateY;
1773
+ var handleMouseEnter = useCallback(function () {
1774
+ var _a, _b;
1775
+ if (data.stepGesture === 'moving')
1776
+ return;
1777
+ startX = ((_b = (_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) === null || _b === void 0 ? void 0 : _b.left) || 0;
1778
+ setVisible(true);
1779
+ }, [data.stepGesture]);
1780
+ var handleMouseLeave = useCallback(function () {
1781
+ if (data.stepGesture === 'moving')
1782
+ return;
1783
+ setVisible(false);
1784
+ store.handleInvalidBarLeave();
1785
+ }, [data.stepGesture, store]);
1786
+ var handleMouseMove = useCallback(function (event) {
1787
+ if (data.stepGesture === 'moving')
1788
+ return;
1789
+ var pointerX = storeTranslateX + (event.clientX - startX);
1790
+ // eslint-disable-next-line no-shadow
1791
+ var _a = store.startXRectBar(pointerX), left = _a.left, width = _a.width;
1792
+ store.handleInvalidBarHover(data, left, Math.ceil(width));
1793
+ setDataTranslateX(left);
1794
+ setDataWidth(Math.ceil(width));
1795
+ }, [data, store, storeTranslateX]);
1796
+ var handleBeforeResize = function () {
1797
+ store.handleInvalidBarDragStart(data);
1798
+ };
1799
+ var handleResize = useCallback(function (_a) {
1800
+ var newWidth = _a.width, x = _a.x;
1801
+ store.updateBarSize(data, { width: newWidth, x: x });
1802
+ setDataWidth(newWidth);
1803
+ setDataTranslateX(x);
1804
+ }, [data, store]);
1805
+ var handleLeftResizeEnd = useCallback(function (oldSize) {
1806
+ store.handleInvalidBarDragEnd(data, oldSize);
1807
+ }, [data, store]);
1808
+ var handleAutoScroll = useCallback(function (delta) {
1809
+ store.setTranslateX(store.translateX + delta);
1810
+ }, [store]);
1811
+ var reachEdge = useMemoizedFn(function (position) { return position === 'left' && store.translateX <= 0; });
1812
+ // Determine the unit of drag according to different views, and take one minute as the unit in any view
1813
+ var grid = useMemo(function () { return ONE_MIN_MS / store.pxUnitAmp; }, [store.pxUnitAmp]);
1814
+ useEffect(function () {
1815
+ setStoreTranslateX(store.translateX);
1816
+ }, [store.translateX]);
1817
+ useEffect(function () {
1818
+ setDataTranslateX(data.translateX);
1819
+ }, [data.translateX]);
1820
+ useEffect(function () {
1821
+ setDataWidth(data.width);
1822
+ }, [data.width]);
1823
+ if (disabled)
1824
+ return null;
1825
+ return (jsxs(DragResize$1, { clickStart: true, defaultSize: {
1826
+ x: dataTranslateX,
1827
+ width: dataWidth,
1828
+ }, grid: grid, minWidth: 30, reachEdge: reachEdge, scroller: store.chartElementRef.current || undefined, type: "right", onAutoScroll: handleAutoScroll, onBeforeResize: handleBeforeResize, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, onMouseMove: handleMouseMove, onResize: handleResize, onResizeEnd: handleLeftResizeEnd, children: [jsx("div", { className: "gantt__invalid-taskbar", ref: triggerRef, style: {
1829
+ left: storeTranslateX,
1830
+ height: rowHeight,
1831
+ transform: "translateY(".concat(top - (rowHeight - barH) / 2, "px"),
1832
+ } }), visible &&
1833
+ renderInvalidBar(jsxs("div", { "aria-expanded": "false", "aria-haspopup": "true", className: "gantt__invalid-taskbar-block", style: {
1834
+ left: dataTranslateX,
1835
+ width: Math.ceil(dataWidth),
1836
+ height: 20,
1837
+ transform: "translateY(".concat(top, "px)"),
1838
+ backgroundColor: '#CAE3B6',
1839
+ borderColor: '#CAE3B6',
1840
+ borderRadius: 8,
1841
+ }, children: [jsx("div", { className: "gantt__invalid-taskbar-date", style: {
1842
+ right: Math.ceil(dataWidth + 6),
1843
+ }, children: dateTextFormat(dataTranslateX) }), jsx("div", { className: "gantt__invalid-taskbar-date", style: {
1844
+ left: Math.ceil(dataWidth + 6),
1845
+ }, children: dateTextFormat(dataTranslateX + dataWidth - dataWidth / store.pxUnitAmp) })] }), data)] }));
1846
+ };
1847
+ var InvalidTaskBar$1 = observer(InvalidTaskBar);
1848
+
1849
+ function EmployeesList(props) {
1850
+ var users = props.users, onClickAddAssignee = props.onClickAddAssignee, _a = props.showCountUsers, showCountUsers = _a === void 0 ? 3 : _a;
1851
+ return (jsxs("div", { className: "employees-list", children: [users.length > 0 &&
1852
+ users.slice(0, showCountUsers).map(function (user) { return (jsx("div", { className: "employees-list__item", children: user.avatar ? (jsx("img", { className: "employees-list__item-image", src: user.avatar })) : (jsxs("div", { className: "employees-list__item-text", children: [user === null || user === void 0 ? void 0 : user.first_name.charAt(0).toUpperCase(), user === null || user === void 0 ? void 0 : user.last_name.charAt(0).toUpperCase()] })) }, user.id)); }), jsx("div", { className: "employees-list__item employees-list__item-text", onClick: onClickAddAssignee, children: jsxs("svg", { fill: "none", height: "8", viewBox: "0 0 8 8", width: "8", xmlns: "http://www.w3.org/2000/svg", children: [jsx("path", { d: "M3.55556 0.444445C3.55556 0.198985 3.75454 0 4 0C4.24546 0 4.44444 0.198985 4.44444 0.444444V7.55556C4.44444 7.80102 4.24546 8 4 8C3.75454 8 3.55556 7.80102 3.55556 7.55556V0.444445Z", fill: "black" }), jsx("path", { d: "M7.55556 3.55556C7.80102 3.55556 8 3.75454 8 4C8 4.24546 7.80102 4.44444 7.55556 4.44444L0.444444 4.44444C0.198985 4.44444 -1.07294e-08 4.24546 0 4C1.07294e-08 3.75454 0.198985 3.55556 0.444444 3.55556L7.55556 3.55556Z", fill: "black" })] }) })] }));
1853
+ }
1854
+ var EmployeesList$1 = observer(EmployeesList);
1855
+
1856
+ var MINUTES_IN_HOUR = 60;
1857
+ var HOURS_IN_DAY = 24;
1858
+ var MINUTES_IN_DAY = MINUTES_IN_HOUR * HOURS_IN_DAY;
1859
+ var TaskBar = function (props) {
1860
+ var _a, _b, _c;
1861
+ var _d;
1862
+ var data = props.data;
1863
+ var _e = useContext(context), alwaysShowTaskBar = _e.alwaysShowTaskBar, barHeight = _e.barHeight, mediaUrl = _e.mediaUrl, renderBar = _e.renderBar, store = _e.store, onBarClick = _e.onBarClick;
1864
+ var rowHeight = store.rowHeight, selectionIndicatorTop = store.selectionIndicatorTop, showSelectionIndicator = store.showSelectionIndicator, taskStatusesChoices = store.taskStatusesChoices;
1865
+ var translateY = data.translateY, getDateWidth = data.getDateWidth, invalidDateRange = data.invalidDateRange, loading = data.loading, record = data.record, stepGesture = data.stepGesture;
1866
+ var _f = useState(data.width), dataWidth = _f[0], setDataWidth = _f[1];
1867
+ var _g = useState(data.translateX), dataTranslateX = _g[0], setDataTranslateX = _g[1];
1868
+ var _h = (record || {}).disabled, disabled = _h === void 0 ? false : _h;
1869
+ var taskUsers = useMemo(function () {
1870
+ var _a, _b, _c, _d;
1871
+ return ((_b = (_a = record === null || record === void 0 ? void 0 : record.task) === null || _a === void 0 ? void 0 : _a.executor_users) === null || _b === void 0 ? void 0 : _b.length)
1872
+ ? (_d = (_c = record === null || record === void 0 ? void 0 : record.task) === null || _c === void 0 ? void 0 : _c.executor_users) === null || _d === void 0 ? void 0 : _d.map(function (user) {
1873
+ var fullAvatarUrl = user.avatar.length > 0 ? mediaUrl + user.avatar.slice(1) : null;
1874
+ return __assign(__assign({}, user), { avatar: fullAvatarUrl });
1875
+ })
1876
+ : [];
1877
+ }, [data, mediaUrl, record]);
1878
+ var showDragBar = useMemo(function () {
1879
+ if (!showSelectionIndicator)
1880
+ return false;
1881
+ var baseTop = TOP_PADDING + rowHeight / 2 - barHeight / 2;
1882
+ return selectionIndicatorTop === translateY - baseTop;
1883
+ }, [showSelectionIndicator, selectionIndicatorTop, translateY, rowHeight, barHeight]);
1884
+ // const themeColor = useMemo(() => {
1885
+ // if (data.translateX + data.width >= dayjs().valueOf() / store.pxUnitAmp) {
1886
+ // return ['#F3F4F6', '#F3F4F6']
1887
+ // }
1888
+ // return ['#74B43D', '#74B43D']
1889
+ // }, [store.pxUnitAmp, data.translateX, data.width])
1890
+ var handleBeforeResize = function (type) { return function () {
1891
+ if (disabled)
1892
+ return;
1893
+ store.handleDragStart(data, type);
1894
+ }; };
1895
+ var handleResize = useCallback(function (_a) {
1896
+ var newWidth = _a.width, x = _a.x;
1897
+ if (disabled)
1898
+ return;
1899
+ var result = store.updateBarSize(data, { width: newWidth, x: x });
1900
+ setDataWidth(result.width);
1901
+ setDataTranslateX(result.translateX);
1902
+ }, [data, store, disabled]);
1903
+ var handleResizeEnd = useCallback(function (oldSize, position) {
1904
+ store.handleDragEnd();
1905
+ store.updateTaskMinutes(data, oldSize, position);
1906
+ }, [data, store]);
1907
+ var handleMoveEnd = useCallback(function (oldSize) {
1908
+ store.handleDragEnd();
1909
+ store.updateTaskMinutes(data, oldSize, 'move');
1910
+ }, [data, store]);
1911
+ var handleAutoScroll = useCallback(function (delta) {
1912
+ store.setTranslateX(store.translateX + delta);
1913
+ }, [store]);
1914
+ var allowDrag = showDragBar && !loading;
1915
+ var handleClick = useCallback(function (e) {
1916
+ e.stopPropagation();
1917
+ if (onBarClick)
1918
+ onBarClick(data.record);
1919
+ }, [data.record, onBarClick]);
1920
+ var reachEdge = useMemoizedFn(function (position) {
1921
+ return position === 'left' && store.translateX <= 0;
1922
+ });
1923
+ var grid = useMemo(function () {
1924
+ return store.sightConfig.type === 'hour'
1925
+ ? (ONE_MIN_MS$1 * 5) / store.pxUnitAmp
1926
+ : ONE_MIN_MS$1 / store.pxUnitAmp;
1927
+ }, [store.pxUnitAmp]);
1928
+ var moveCalc = -(dataWidth / store.pxUnitAmp);
1929
+ var barTime = useMemo(function () {
1930
+ var fullDaysWidth = Math.max(Number(dayjs((dataTranslateX + dataWidth + moveCalc) * store.pxUnitAmp).diff(dayjs(Math.ceil(dataTranslateX) * store.pxUnitAmp), 'minute')), 0);
1931
+ switch (store.sightConfig.type) {
1932
+ case 'hour':
1933
+ return fullDaysWidth > MINUTES_IN_HOUR - 1
1934
+ ? formatHours(Math.floor(fullDaysWidth / MINUTES_IN_HOUR))
1935
+ : formatMinutes(fullDaysWidth);
1936
+ case 'day':
1937
+ if (fullDaysWidth < HOURS_IN_DAY * MINUTES_IN_HOUR) {
1938
+ var hoursWidth = Number(getDateWidth(dataTranslateX + dataWidth + moveCalc, dataTranslateX, 'hour'));
1939
+ return formatHours(hoursWidth);
1940
+ }
1941
+ break;
1942
+ }
1943
+ if (fullDaysWidth >= MINUTES_IN_DAY) {
1944
+ return formatDays(Math.floor(fullDaysWidth / MINUTES_IN_DAY));
1945
+ }
1946
+ else if (fullDaysWidth >= MINUTES_IN_HOUR) {
1947
+ return formatHours(Math.floor(fullDaysWidth / MINUTES_IN_HOUR));
1948
+ }
1949
+ return formatMinutes(fullDaysWidth);
1950
+ }, [dataTranslateX, dataWidth, moveCalc, store.sightConfig.type, getDateWidth]);
1951
+ useEffect(function () {
1952
+ setDataWidth(data.width);
1953
+ setDataTranslateX(data.translateX);
1954
+ }, [data.width, data.translateX]);
1955
+ // prettier-ignore
1956
+ var taskBackgroundColor = (((_d = taskStatusesChoices[data.record.task.status]) === null || _d === void 0 ? void 0 : _d.backgroundColor) || 'hsla(0, 0%, 93%, 1)');
1957
+ return (jsxs("div", { className: classNames('gantt__taskbar', (_a = {},
1958
+ _a["gantt__taskbar-invalid-date-range"] = invalidDateRange,
1959
+ _a["gantt__taskbar-overdue"] = !invalidDateRange,
1960
+ _a)), role: "none", style: {
1961
+ transform: "translate(".concat(dataTranslateX, "px, ").concat(translateY, "px)"),
1962
+ }, onClick: handleClick, children: [loading && jsx("div", { className: "gantt__taskbar-loading" }), jsxs("div", { children: [allowDrag && (jsxs(React.Fragment, { children: [jsx(DragResize$1, { className: classNames("gantt__taskbar-resize-handle", "gantt__taskbar-resize-handle-left", (_b = {},
1963
+ _b["gantt__taskbar-resize-handle-disabled"] = disabled,
1964
+ _b)), minWidth: 5, disabled: disabled, grid: grid, reachEdge: reachEdge, scroller: store.chartElementRef.current || undefined, style: { left: -7 }, type: "left", defaultSize: {
1965
+ width: dataWidth,
1966
+ x: dataTranslateX,
1967
+ }, onAutoScroll: handleAutoScroll, onBeforeResize: handleBeforeResize('left'), onResize: handleResize, onResizeEnd: function (oldSize) { return handleResizeEnd(oldSize, 'left'); } }), jsx(DragResize$1, { className: classNames("gantt__taskbar-resize-handle", "gantt__taskbar-resize-handle-right", (_c = {},
1968
+ _c["gantt__taskbar-resize-handle-disabled"] = disabled,
1969
+ _c)), minWidth: 5, disabled: disabled, grid: grid, reachEdge: reachEdge, scroller: store.chartElementRef.current || undefined, style: { left: dataWidth - 8 }, type: "right", defaultSize: {
1970
+ width: dataWidth,
1971
+ x: dataTranslateX,
1972
+ }, onAutoScroll: handleAutoScroll, onBeforeResize: handleBeforeResize('right'), onResize: handleResize, onResizeEnd: function (oldSize) { return handleResizeEnd(oldSize, 'right'); } }), jsx("div", { className: classNames("gantt__taskbar-resize-bg", "gantt__taskbar-resize-bg-compact"), style: { width: dataWidth + 1, left: 0 } })] })), jsx(DragResize$1, { className: "gantt__taskbar-bar", minWidth: 5, grid: grid, reachEdge: reachEdge, scroller: store.chartElementRef.current || undefined, style: { backgroundColor: taskBackgroundColor }, type: "move", defaultSize: {
1973
+ width: dataWidth,
1974
+ x: dataTranslateX,
1975
+ }, onAutoScroll: handleAutoScroll, onBeforeResize: handleBeforeResize('move'), onResize: handleResize, onResizeEnd: handleMoveEnd, children: renderBar ? (renderBar(data, {
1976
+ width: dataWidth + 1,
1977
+ height: barHeight + 1,
1978
+ })) : (jsx("div", { style: { width: dataWidth, height: barHeight } })
1979
+ // <svg
1980
+ // height={barHeight + 1}
1981
+ // version="1.1"
1982
+ // viewBox={`0 0 ${dataWidth + 1} ${barHeight + 1}`}
1983
+ // width={dataWidth + 1}
1984
+ // xmlns="http://www.w3.org/2000/svg"
1985
+ // >
1986
+ // <path
1987
+ // d={`
1988
+ // M${dataWidth - 2},0.5
1989
+ // l-${dataWidth - 5},0
1990
+ // c-0.41421,0 -0.78921,0.16789 -1.06066,0.43934
1991
+ // c-0.27145,0.27145 -0.43934,0.64645 -0.43934,1.06066
1992
+ // l0,5.3
1993
+ // c0.03256,0.38255 0.20896,0.724 0.47457,0.97045
1994
+ // c0.26763,0.24834 0.62607,0.40013 1.01995,0.40013
1995
+ // l4,0
1996
+ // l${Math.max(dataWidth - 12, 0)},0
1997
+ // l4,0
1998
+ // c0.41421,0 0.78921,-0.16789 1.06066,-0.43934
1999
+ // c0.27145,-0.27145 0.43934,-0.64645 0.43934,-1.06066
2000
+ // l0,-5.3
2001
+ // c-0.03256,-0.38255 -0.20896,-0.724 -0.47457,-0.97045
2002
+ // c-0.26763,-0.24834 -0.62607,-0.40013 -1.01995,-0.40013z
2003
+ // `}
2004
+ // fill={
2005
+ // record.backgroundColor ||
2006
+ // (getBarColor && getBarColor(record).backgroundColor) ||
2007
+ // themeColor[0]
2008
+ // }
2009
+ // stroke={
2010
+ // record.borderColor ||
2011
+ // (getBarColor && getBarColor(record).borderColor) ||
2012
+ // themeColor[1]
2013
+ // }
2014
+ // />
2015
+ // </svg>
2016
+ ) })] }), (stepGesture === 'moving' || allowDrag || alwaysShowTaskBar) && (jsx(React.Fragment, { children: jsxs("div", { className: "gantt__taskbar-date-text", style: { left: dataWidth + 16 }, children: [jsx(EmployeesList$1, { users: taskUsers, onClickAddAssignee: function () {
2017
+ store.onAddTaskAssignee(record.task.id);
2018
+ } }), barTime] }) }))] }));
2019
+ };
2020
+ var TaskBar$1 = observer(TaskBar);
2021
+
2022
+ var BarList = function () {
2023
+ var store = useContext(context).store;
2024
+ var getBarList = store.getBarList, getVisibleRows = store.getVisibleRows;
2025
+ var start = getVisibleRows.start, count = getVisibleRows.count;
2026
+ var visibleBars = getBarList.slice(start, start + count);
2027
+ if ((visibleBars === null || visibleBars === void 0 ? void 0 : visibleBars.length) > 0) {
2028
+ return (jsx(React.Fragment, { children: visibleBars.map(function (bar, index) {
2029
+ var _a, _b;
2030
+ var barKey = "bar-".concat(bar.key, "-").concat(index);
2031
+ if (bar.isGroupRow && ((_b = (_a = bar === null || bar === void 0 ? void 0 : bar.record) === null || _a === void 0 ? void 0 : _a.tasks) === null || _b === void 0 ? void 0 : _b.length)) {
2032
+ return jsx(GroupBar$1, { data: bar }, barKey);
2033
+ }
2034
+ if (bar.invalidDateRange) {
2035
+ return jsx(InvalidTaskBar$1, { data: bar }, barKey);
2036
+ }
2037
+ if (bar.record.task) {
2038
+ return jsx(TaskBar$1, { data: bar }, barKey);
2039
+ }
2040
+ }) }));
2041
+ }
2042
+ return null;
2043
+ };
2044
+ var BarList$1 = observer(BarList);
2045
+
2046
+ var spaceX = 10;
2047
+ var spaceY = 10;
2048
+ /**
2049
+ * Get key points
2050
+ *
2051
+ * @param from
2052
+ * @param to
2053
+ */
2054
+ function getPoints(from, to, type) {
2055
+ var fromX = from.x, fromY = from.y;
2056
+ var toX = to.x, toY = to.y;
2057
+ var sameSide = type === 'finish_finish' || type === 'start_start';
2058
+ // In the same direction, only two key points are needed
2059
+ if (sameSide) {
2060
+ if (type === 'start_start') {
2061
+ return [
2062
+ { x: Math.min(fromX - spaceX, toX - spaceX), y: fromY },
2063
+ { x: Math.min(fromX - spaceX, toX - spaceX), y: toY },
2064
+ ];
2065
+ }
2066
+ return [
2067
+ { x: Math.max(fromX + spaceX, toX + spaceX), y: fromY },
2068
+ { x: Math.max(fromX + spaceX, toX + spaceX), y: toY },
2069
+ ];
2070
+ }
2071
+ // Different directions require four key points
2072
+ return [
2073
+ { x: type === 'finish_start' ? fromX + spaceX : fromX - spaceX, y: fromY },
2074
+ {
2075
+ x: type === 'finish_start' ? fromX + spaceX : fromX - spaceX,
2076
+ y: toY - spaceY,
2077
+ },
2078
+ {
2079
+ x: type === 'finish_start' ? toX - spaceX : toX + spaceX,
2080
+ y: toY - spaceY,
2081
+ },
2082
+ { x: type === 'finish_start' ? toX - spaceX : toX + spaceX, y: toY },
2083
+ ];
2084
+ }
2085
+ var Dependence = function (_a) {
2086
+ var data = _a.data;
2087
+ var _b = useContext(context), store = _b.store, barHeight = _b.barHeight;
2088
+ var from = data.from, to = data.to, type = data.type, _c = data.color, color = _c === void 0 ? '#f87872' : _c;
2089
+ var barList = store.getBarList;
2090
+ var fromBar = find(barList, function (bar) { return !bar.isGroupRow && String(bar.record.id) === String(from); });
2091
+ var toBar = find(barList, function (bar) { return !bar.isGroupRow && String(bar.record.id) === String(to); });
2092
+ if (!fromBar || !toBar) {
2093
+ return null;
2094
+ }
2095
+ var posY = barHeight / 2;
2096
+ var _d = (function () { return [
2097
+ {
2098
+ x: type === 'finish_finish' || type === 'finish_start'
2099
+ ? fromBar.translateX + fromBar.width
2100
+ : fromBar.translateX,
2101
+ y: fromBar.translateY + posY,
2102
+ },
2103
+ {
2104
+ x: type === 'finish_finish' || type === 'start_finish'
2105
+ ? toBar.translateX + toBar.width
2106
+ : toBar.translateX,
2107
+ y: toBar.translateY + posY,
2108
+ },
2109
+ ]; })(), start = _d[0], end = _d[1];
2110
+ var points = __spreadArray(__spreadArray([], getPoints(start, end, type), true), [end], false);
2111
+ var endPosition = type === 'start_finish' || type === 'finish_finish' ? -1 : 1;
2112
+ return (jsxs("g", { className: 'task-dependency-line', stroke: color, children: [jsx("path", { d: "\n M".concat(start.x, ",").concat(start.y, "\n ").concat(points.map(function (point) { return "L".concat(Math.max(point.x), ",").concat(point.y); }).join('\n'), "\n L").concat(Math.max(end.x, 0), ",").concat(end.y, "\n "), fill: "none", strokeWidth: "1", style: { stroke: color } }), jsx("path", { d: "\n M".concat(end.x, ",").concat(end.y, "\n L").concat(Math.max(end.x - 4 * endPosition, 0), ",").concat(Math.max(end.y - 3 * endPosition, 0), "\n L").concat(Math.max(end.x - 4 * endPosition, 0), ",").concat(Math.max(end.y + 3 * endPosition, 0), "\n Z"), fill: color, name: "arrow", strokeWidth: "1" })] }));
2113
+ };
2114
+ jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", version: "1.1", "xmlns:xlink": "http://www.w3.org/1999/xlink", "xmlns:svgjs": "http://svgjs.dev/svgjs", viewBox: "0 0 1422 800", children: [jsx("g", { "stroke-width": "10", stroke: "hsl(10, 75%, 40%)", fill: "none", "stroke-linecap": "square", transform: "matrix(1,0,0,1,-94,-98)", children: jsx("polyline", { points: "603,288.5 819,288.5 819,511.5", "marker-end": "url(#SvgjsMarker1636)" }) }), jsx("defs", { children: jsx("marker", { markerWidth: "4", markerHeight: "4", refX: "2", refY: "2", viewBox: "0 0 4 4", orient: "auto", id: "SvgjsMarker1636", children: jsx("polygon", { points: "1.3333333333333333,4 0,2 1.3333333333333333,0 4,2", fill: "hsl(10, 75%, 40%)" }) }) })] });
2115
+ var Dependence$1 = observer(Dependence);
2116
+
2117
+ var Dependencies = function () {
2118
+ var store = useContext(context).store;
2119
+ var dependencies = store.dependencies;
2120
+ // const _dependencies = [
2121
+ // {
2122
+ // from: '103',
2123
+ // to: '104',
2124
+ // type: 'finish_start',
2125
+ // color: 'blue',
2126
+ // },
2127
+ // {
2128
+ // from: '104',
2129
+ // to: '105',
2130
+ // type: 'finish_start',
2131
+ // },
2132
+ // ]
2133
+ return (jsx(React.Fragment, { children: dependencies.map(function (dependence) { return (jsx(Dependence$1, { data: dependence }, JSON.stringify(dependence))); }) }));
2134
+ };
2135
+ var Dependencies$1 = observer(Dependencies);
2136
+
2137
+ /**
2138
+ * Dragging prompt line
2139
+ */
2140
+ var DragPresent = function () {
2141
+ var store = useContext(context).store;
2142
+ var dragging = store.dragging, draggingType = store.draggingType, bodyScrollHeight = store.bodyScrollHeight;
2143
+ if (!dragging)
2144
+ return null;
2145
+ // Same length as the current dragging block
2146
+ var width = dragging.width, translateX = dragging.translateX;
2147
+ var left = translateX;
2148
+ var right = translateX + width;
2149
+ var leftLine = draggingType === 'left' || draggingType === 'move';
2150
+ var rightLine = draggingType === 'right' || draggingType === 'move';
2151
+ return (jsxs("g", { fill: "#DAE0FF", stroke: "#7B90FF", children: [leftLine && jsx("path", { d: "M".concat(left, ",0 L").concat(Math.max(left, 0), ",").concat(bodyScrollHeight) }), jsx("rect", { height: bodyScrollHeight, strokeWidth: "0", width: width, x: left, y: "0" }), rightLine && jsx("path", { d: "M".concat(right, ",0 L").concat(Math.max(right, 0), ",").concat(bodyScrollHeight) })] }));
2152
+ };
2153
+ var DragPresent$1 = observer(DragPresent);
2154
+
2155
+ var Today = function () {
2156
+ var store = useContext(context).store;
2157
+ var timeUnit = store.sightConfig.type;
2158
+ return (jsx("div", { className: "gantt__today", style: {
2159
+ transform: "translateX(".concat(store.todayTranslateX + (timeUnit === 'week' ? 10 : 0), "px)"),
2160
+ width: store.getWidthByDate(dayjs().startOf(timeUnit), dayjs().startOf(timeUnit).add(1, timeUnit)),
2161
+ opacity: 0.15,
2162
+ height: store.bodyScrollHeight,
2163
+ borderRadius: 0,
2164
+ } }));
2165
+ };
2166
+ var Today$1 = observer(Today);
2167
+
2168
+ var Chart = function () {
2169
+ var store = useContext(context).store;
2170
+ var translateX = store.translateX, bodyScrollHeight = store.bodyScrollHeight, chartElementRef = store.chartElementRef, tableWidth = store.tableWidth, viewWidth = store.viewWidth;
2171
+ var minorList = store.getMinorList();
2172
+ var handleMouseMove = useCallback(function (event) {
2173
+ event.persist();
2174
+ store.handleMouseMove(event);
2175
+ }, [store]);
2176
+ var handleMouseLeave = useCallback(function () {
2177
+ store.handleMouseLeave();
2178
+ }, [store]);
2179
+ useEffect(function () {
2180
+ var element = chartElementRef.current;
2181
+ if (element)
2182
+ element.addEventListener('wheel', store.handleWheel);
2183
+ return function () {
2184
+ if (element)
2185
+ element.removeEventListener('wheel', store.handleWheel);
2186
+ };
2187
+ }, [chartElementRef, store]);
2188
+ return (jsxs("div", { className: "gantt__chart", ref: chartElementRef, style: {
2189
+ width: viewWidth,
2190
+ height: bodyScrollHeight,
2191
+ left: tableWidth,
2192
+ }, onMouseLeave: handleMouseLeave, onMouseMove: handleMouseMove, children: [jsxs("svg", { className: "gantt__chart-svg-renderer", width: viewWidth, height: bodyScrollHeight, style: { shapeRendering: 'crispEdges' }, version: "1.1", viewBox: "".concat(translateX, " 0 ").concat(viewWidth, " ").concat(bodyScrollHeight), xmlns: "http://www.w3.org/2000/svg", children: [jsx("defs", { children: jsx("pattern", { width: "4.5", height: "10", id: "repeat", patternTransform: "rotate(70 50 50)", patternUnits: "userSpaceOnUse", children: jsx("line", { stroke: "grey", strokeWidth: "1px", y2: "10" }) }) }), minorList.map(function (item) {
2193
+ return store.sightConfig.type !== 'hour' ? (item.isWeek ? (jsxs("g", { stroke: "#E5E5E5", children: [jsx("path", { d: "M".concat(item.left, ",0 L").concat(Math.max(item.left, 0), ",").concat(bodyScrollHeight) }), jsx("rect", { width: item.width, height: bodyScrollHeight, fill: "#D9D9D9", opacity: "1", strokeWidth: "0", x: item.left, y: 0 })] }, item.key)) : (jsx("g", { stroke: "#E5E5E5", children: jsx("path", { d: "M".concat(item.left, ",0 L").concat(Math.max(item.left, 0), ",").concat(bodyScrollHeight) }) }, item.key))) : (jsx("g", { stroke: "#E5E5E5", children: jsx("rect", { width: item.width, height: bodyScrollHeight, fill: "transparent", opacity: "1", strokeWidth: "1.5", x: item.left, y: 0 }) }, item.key));
2194
+ }), jsx(DragPresent$1, {}), jsx(Dependencies$1, {})] }), jsxs("div", { className: "gantt__chart-render-chunk", style: {
2195
+ height: bodyScrollHeight,
2196
+ transform: "translateX(-".concat(translateX, "px"),
2197
+ }, children: [jsx(BarList$1, {}), jsx(Today$1, {})] })] }));
2198
+ };
2199
+ var Chart$1 = memo(observer(Chart));
2200
+
2201
+ function useDragResize(handleResize, _a) {
2202
+ var _this = this;
2203
+ var initSize = _a.initSize, minWidthConfig = _a.minWidth, maxWidthConfig = _a.maxWidth;
2204
+ var _b = useState(false), resizing = _b[0], setResizing = _b[1];
2205
+ var positionRef = useRef({
2206
+ left: 0,
2207
+ });
2208
+ var initSizeRef = useRef(initSize);
2209
+ var handleMouseMove = useMemoizedFn(function (event) { return __awaiter(_this, void 0, void 0, function () {
2210
+ var distance, width;
2211
+ return __generator(this, function (_a) {
2212
+ distance = event.clientX - positionRef.current.left;
2213
+ width = initSizeRef.current.width + distance;
2214
+ width = Math.max(width, minWidthConfig);
2215
+ if (maxWidthConfig !== undefined)
2216
+ width = Math.min(width, maxWidthConfig);
2217
+ handleResize({ width: width });
2218
+ return [2 /*return*/];
2219
+ });
2220
+ }); });
2221
+ var handleMouseUp = useCallback(function () {
2222
+ window.removeEventListener('mousemove', handleMouseMove);
2223
+ window.removeEventListener('mouseup', handleMouseUp);
2224
+ setResizing(false);
2225
+ }, [handleMouseMove]);
2226
+ var handleMouseDown = useCallback(function (event) {
2227
+ positionRef.current.left = event.clientX;
2228
+ initSizeRef.current = initSize;
2229
+ window.addEventListener('mousemove', handleMouseMove);
2230
+ window.addEventListener('mouseup', handleMouseUp);
2231
+ setResizing(true);
2232
+ }, [handleMouseMove, handleMouseUp, initSize]);
2233
+ return [handleMouseDown, resizing];
2234
+ }
2235
+
2236
+ var Divider = function () {
2237
+ var _a, _b;
2238
+ var _c = useContext(context), store = _c.store, tableCollapseAble = _c.tableCollapseAble;
2239
+ var tableWidth = store.tableWidth;
2240
+ var _d = useState(tableWidth), currentWidth = _d[0], setCurrentWidth = _d[1];
2241
+ var handleClick = useCallback(function (event) {
2242
+ event.stopPropagation();
2243
+ store.toggleCollapse();
2244
+ }, [store]);
2245
+ var handleResize = useCallback(function (_a) {
2246
+ var width = _a.width;
2247
+ store.handleResizeTableWidth(width);
2248
+ setCurrentWidth(width);
2249
+ }, [store]);
2250
+ var _e = useDragResize(handleResize, {
2251
+ initSize: {
2252
+ width: tableWidth,
2253
+ },
2254
+ minWidth: 200,
2255
+ maxWidth: store.width * 0.6,
2256
+ }), handleMouseDown = _e[0], resizing = _e[1];
2257
+ useEffect(function () {
2258
+ setCurrentWidth(tableWidth);
2259
+ }, [tableWidth]);
2260
+ return (jsxs("div", { className: classNames('gantt__divider', (_a = {},
2261
+ _a["gantt__divider-only"] = !tableCollapseAble,
2262
+ _a)), role: "none", style: { left: currentWidth }, onMouseDown: currentWidth === 0 ? undefined : handleMouseDown, children: [resizing && (jsx("div", { style: {
2263
+ position: 'fixed',
2264
+ top: 0,
2265
+ left: 0,
2266
+ bottom: 0,
2267
+ right: 0,
2268
+ zIndex: 9999,
2269
+ cursor: 'col-resize',
2270
+ } })), jsx("hr", {}), tableCollapseAble && (jsx("div", { className: "gantt__divider-icon-wrapper", role: "none", onClick: handleClick, onMouseDown: function (e) { return e.stopPropagation(); }, children: jsx("i", { className: classNames("gantt__divider-arrow", (_b = {},
2271
+ _b["gantt__divider-reverse"] = currentWidth <= 0,
2272
+ _b)) }) }))] }));
2273
+ };
2274
+ var Divider$1 = observer(Divider);
2275
+
2276
+ var Scale = function (props) {
2277
+ var _a = useState(0), currentStep = _a[0], setCurrentStep = _a[1];
2278
+ var steps = props.steps;
2279
+ var handleStep = function (stepNum) {
2280
+ setCurrentStep(stepNum);
2281
+ };
2282
+ return (jsxs("div", { className: "gantt__scale", children: [jsx("span", { className: "gantt__scale-text", children: "\u041C\u0430\u0441\u0448\u0442\u0430\u0431" }), jsxs("div", { className: "gantt__scale-container", children: [jsx("div", { className: "gantt__scale-progress", children: jsx("div", { className: "gantt__scale-percent", style: { width: "".concat(currentStep * (100 / steps), "%") } }) }), jsx("div", { className: "gantt__scale-steps", children: __spreadArray([], Array(steps + 1).keys(), true).map(function (step) { return (jsx("div", { className: "gantt__scale-step ".concat(step === currentStep ? 'selected' : '', " ").concat(step < currentStep ? 'completed' : ''), onClick: function () { return handleStep(step); } }, step)); }) })] }), jsxs("span", { className: "gantt__scale-text gantt__scale-text-fixed", children: [Math.round(currentStep * (100 / steps)), "%"] })] }));
2283
+ };
2284
+
2285
+ var Header = function () {
2286
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2287
+ var _a = useState(false); _a[0]; var setVisible = _a[1];
2288
+ var store = useContext(context).store;
2289
+ var sightConfig = store.sightConfig, viewTypeList = store.viewTypeList;
2290
+ var ref = useRef(null);
2291
+ useClickAway(function () {
2292
+ setVisible(false);
2293
+ }, ref);
2294
+ var handleClick = useCallback(function () {
2295
+ setVisible(true);
2296
+ }, []);
2297
+ var handleSelect = useCallback(function (item) {
2298
+ store.switchSight(item.type);
2299
+ setVisible(false);
2300
+ }, [store]);
2301
+ var selected = sightConfig.type;
2302
+ var isSelected = useCallback(function (key) { return key === selected; }, [selected]);
2303
+ return (jsxs("div", { className: "gantt__header", ref: ref, children: [jsx(Scale, { steps: 4 }), jsxs("div", { className: "gantt__period", role: "none", onClick: handleClick, children: [jsx("span", { className: "gantt__period-text", children: "\u0412\u0438\u0434:" }), jsx("ul", { "aria-multiselectable": "false", className: classNames('gantt__period-menu'), role: "listbox", children: viewTypeList.map(function (item) { return (jsx("li", { className: classNames('gantt__period-menu-item', {
2304
+ 'gantt__period-selected': isSelected(item.type),
2305
+ }), role: "none", onClick: function () {
2306
+ handleSelect(item);
2307
+ }, children: jsx("span", { "aria-selected": "true", children: item.label }) }, item.type)); }) })] })] }));
2308
+ };
2309
+ var Header$1 = observer(Header);
2310
+
2311
+ var ScrollBar = function () {
2312
+ var store = useContext(context).store;
2313
+ var tableWidth = store.tableWidth, viewWidth = store.viewWidth;
2314
+ var width = store.scrollBarWidth;
2315
+ var _a = useState(false), resizing = _a[0], setResizing = _a[1];
2316
+ var positionRef = useRef({
2317
+ scrollLeft: 0,
2318
+ left: 0,
2319
+ translateX: 0,
2320
+ });
2321
+ var handleMouseMove = useMemoizedFn(function (event) {
2322
+ var distance = event.clientX - positionRef.current.left;
2323
+ // TODO: Adjust the magnification
2324
+ store.setTranslateX(distance * (store.viewWidth / store.scrollBarWidth) + positionRef.current.translateX);
2325
+ });
2326
+ var handleMouseUp = useCallback(function () {
2327
+ window.removeEventListener('mousemove', handleMouseMove);
2328
+ window.removeEventListener('mouseup', handleMouseUp);
2329
+ setResizing(false);
2330
+ }, [handleMouseMove]);
2331
+ var handleMouseDown = useCallback(function (event) {
2332
+ positionRef.current.left = event.clientX;
2333
+ positionRef.current.translateX = store.translateX;
2334
+ positionRef.current.scrollLeft = store.scrollLeft;
2335
+ window.addEventListener('mousemove', handleMouseMove);
2336
+ window.addEventListener('mouseup', handleMouseUp);
2337
+ setResizing(true);
2338
+ }, [handleMouseMove, handleMouseUp, store.scrollLeft, store.translateX]);
2339
+ return (jsxs("div", { className: "gantt__scrollbar", role: "none", style: { left: tableWidth, width: viewWidth }, onMouseDown: handleMouseDown, children: [resizing && (jsx("div", { style: {
2340
+ position: 'fixed',
2341
+ top: 0,
2342
+ left: 0,
2343
+ bottom: 0,
2344
+ right: 0,
2345
+ zIndex: 9999,
2346
+ cursor: 'col-resize',
2347
+ } })), jsx("div", { className: "gantt__scrollbar-thumb", style: {
2348
+ width: width,
2349
+ left: store.scrollLeft,
2350
+ minWidth: '50px',
2351
+ transition: 'width 0.2s ease-out',
2352
+ } })] }));
2353
+ };
2354
+ var ScrollBar$1 = memo(observer(ScrollBar));
2355
+
2356
+ var ScrollTop = function () {
2357
+ var _a = useContext(context), store = _a.store, scrollTopConfig = _a.scrollTop;
2358
+ var scrollTop = store.scrollTop;
2359
+ var handleClick = useCallback(function () {
2360
+ if (store.mainElementRef.current)
2361
+ store.mainElementRef.current.scrollTop = 0;
2362
+ }, [store.mainElementRef]);
2363
+ if (scrollTop <= 100 || !store.mainElementRef.current)
2364
+ return null;
2365
+ return (jsx("div", { className: "gantt__scrolltop", style: scrollTopConfig instanceof Object ? scrollTopConfig : undefined, onClick: handleClick }));
2366
+ };
2367
+ var ScrollTop$1 = observer(ScrollTop);
2368
+
2369
+ /**
2370
+ * Mouse hover effect simulation
2371
+ */
2372
+ var SelectionIndicator = function () {
2373
+ var store = useContext(context).store;
2374
+ var showSelectionIndicator = store.showSelectionIndicator, selectionIndicatorTop = store.selectionIndicatorTop, rowHeight = store.rowHeight;
2375
+ return showSelectionIndicator ? (jsx("div", { className: "gantt__selection-indicator", style: {
2376
+ height: rowHeight,
2377
+ top: selectionIndicatorTop,
2378
+ } })) : null;
2379
+ };
2380
+ var SelectionIndicator$1 = observer(SelectionIndicator);
2381
+
2382
+ var GroupContainer = forwardRef(function GroupContainer(props, ref) {
2383
+ var children = props.children, _a = props.columns, columns = _a === void 0 ? 1 : _a, groupData = props.groupData, handleProps = props.handleProps, handleToggleCollapse = props.handleToggleCollapse, placeholder = props.placeholder, style = props.style, onClick = props.onClick, otherProps = __rest(props
2384
+ // const Component = onClick ? 'button' : 'div'
2385
+ , ["children", "columns", "groupData", "handleProps", "handleToggleCollapse", "placeholder", "style", "onClick"]);
2386
+ // const Component = onClick ? 'button' : 'div'
2387
+ var store = React.useContext(context).store;
2388
+ var columnsWidth = store.getColumnsWidth;
2389
+ return (jsxs("div", __assign({}, otherProps, { ref: ref, style: __assign(__assign({}, style), { '--columns': columns }) }, handleProps, { tabIndex: onClick ? 0 : undefined, onClick: onClick, children: [jsx("div", { className: 'groupRow', children: store.columns.map(function (column, cellIndex) { return (column.renderGroupCell && (jsx("div", { style: __assign({ width: columnsWidth[cellIndex], height: '100%', minWidth: column.minWidth, maxWidth: column.maxWidth, textAlign: column.align ? column.align : 'left', display: 'flex' }, column.style), onMouseDown: function (event) {
2390
+ if (column.isDraggableColumn === false) {
2391
+ event.stopPropagation();
2392
+ }
2393
+ }, children: column.renderGroupCell(groupData, handleToggleCollapse) }, cellIndex))); }) }), placeholder ? children : jsx("ul", { style: { margin: 0, padding: 0 }, children: children })] })));
2394
+ });
2395
+
2396
+ // eslint-disable-next-line react/display-name
2397
+ var Action = forwardRef(function (_a, ref) {
2398
+ _a.active; var cursor = _a.cursor, style = _a.style, props = __rest(_a, ["active", "cursor", "style"]);
2399
+ return (jsx("button", __assign({ ref: ref }, props, { style: __assign(__assign({}, style), { border: 'none', cursor: cursor, fill: '#000', background: 'transparent' }), tabIndex: 0 })));
2400
+ });
2401
+
2402
+ // eslint-disable-next-line react/display-name
2403
+ var Handle = forwardRef(function (props, ref) {
2404
+ return (jsx(Action, __assign({ cursor: "grab", "data-cypress": "draggable-handle", ref: ref }, props, { children: jsx("svg", { viewBox: "0 0 20 20", width: "12", children: jsx("path", { d: "M7 2a2 2 0 1 0 .001 4.001A2 2 0 0 0 7 2zm0 6a2 2 0 1 0 .001 4.001A2 2 0 0 0 7 8zm0 6a2 2 0 1 0 .001 4.001A2 2 0 0 0 7 14zm6-8a2 2 0 1 0-.001-4.001A2 2 0 0 0 13 6zm0 2a2 2 0 1 0 .001 4.001A2 2 0 0 0 13 8zm0 6a2 2 0 1 0 .001 4.001A2 2 0 0 0 13 14z" }) }) })));
2405
+ });
2406
+
2407
+ function Remove(props) {
2408
+ return (jsx(Action, __assign({}, props, { children: jsx("svg", { viewBox: "0 0 22 22", width: "8", xmlns: "http://www.w3.org/2000/svg", children: jsx("path", { d: "M2.99998 -0.000206962C2.7441 -0.000206962 2.48794 0.0972617 2.29294 0.292762L0.292945 2.29276C-0.0980552 2.68376 -0.0980552 3.31682 0.292945 3.70682L7.58591 10.9998L0.292945 18.2928C-0.0980552 18.6838 -0.0980552 19.3168 0.292945 19.7068L2.29294 21.7068C2.68394 22.0978 3.31701 22.0978 3.70701 21.7068L11 14.4139L18.2929 21.7068C18.6829 22.0978 19.317 22.0978 19.707 21.7068L21.707 19.7068C22.098 19.3158 22.098 18.6828 21.707 18.2928L14.414 10.9998L21.707 3.70682C22.098 3.31682 22.098 2.68276 21.707 2.29276L19.707 0.292762C19.316 -0.0982383 18.6829 -0.0982383 18.2929 0.292762L11 7.58573L3.70701 0.292762C3.51151 0.0972617 3.25585 -0.000206962 2.99998 -0.000206962Z" }) }) })));
2409
+ }
2410
+
2411
+ var Item = React.memo(React.forwardRef(function Item(props, ref) {
2412
+ var color = props.color, dragOverlay = props.dragOverlay, dragging = props.dragging, fadeIn = props.fadeIn, handle = props.handle, handleProps = props.handleProps, height = props.height, index = props.index, listeners = props.listeners, onRemove = props.onRemove, renderItem = props.renderItem, sorting = props.sorting, style = props.style, transition = props.transition, transform = props.transform, wrapperStyle = props.wrapperStyle, children = props.children, itemProps = __rest(props, ["color", "dragOverlay", "dragging", "fadeIn", "handle", "handleProps", "height", "index", "listeners", "onRemove", "renderItem", "sorting", "style", "transition", "transform", "wrapperStyle", "children"]);
2413
+ useEffect(function () {
2414
+ if (dragOverlay) {
2415
+ document.body.style.cursor = 'grabbing';
2416
+ return function () {
2417
+ document.body.style.cursor = '';
2418
+ };
2419
+ }
2420
+ }, [dragOverlay]);
2421
+ if (renderItem) {
2422
+ return renderItem({
2423
+ dragOverlay: Boolean(dragOverlay),
2424
+ dragging: Boolean(dragging),
2425
+ sorting: Boolean(sorting),
2426
+ index: index,
2427
+ fadeIn: Boolean(fadeIn),
2428
+ listeners: listeners,
2429
+ ref: ref,
2430
+ style: style,
2431
+ transform: transform,
2432
+ transition: transition,
2433
+ });
2434
+ }
2435
+ return (jsx("li", __assign({ ref: ref, style: __assign(__assign({}, wrapperStyle), { listStyle: 'none', height: height ? "".concat(height, "px") : '40px', background: '#fff', borderBottom: '1px solid #E5E5E5', transition: [transition, wrapperStyle === null || wrapperStyle === void 0 ? void 0 : wrapperStyle.transition].filter(Boolean).join(', '), '--translate-x': transform ? "".concat(Math.round(transform.x), "px") : undefined, '--translate-y': transform ? "".concat(Math.round(transform.y), "px") : undefined, '--scale-x': (transform === null || transform === void 0 ? void 0 : transform.scaleX) ? "".concat(transform.scaleX) : undefined, '--scale-y': (transform === null || transform === void 0 ? void 0 : transform.scaleY) ? "".concat(transform.scaleY) : undefined, '--index': index, '--color': color }) }, (!handle ? listeners : undefined), { tabIndex: !handle ? 0 : undefined, children: jsxs("div", __assign({ className: "taskRow" }, itemProps, { children: [children, Boolean(onRemove || handle) && (jsxs("div", { children: [onRemove ? jsx(Remove, { onClick: onRemove }) : null, handle ? jsx(Handle, __assign({}, handleProps, listeners)) : null] }))] })) })));
2436
+ }));
2437
+
2438
+ function DragGroupOverlay(props) {
2439
+ var _a, _b;
2440
+ var groupId = props.groupId, handle = props.handle, items = props.items, placeId = props.placeId, renderItem = props.renderItem;
2441
+ var store = useContext(context).store;
2442
+ var columns = store.columns, getColumnsWidth = store.getColumnsWidth;
2443
+ var extractedContainerId = String(groupId).replace('_group', '');
2444
+ var isGroupCollapsed = (_a = store.getAllGroupRecordsList.find(function (group) { return String(group.id) === extractedContainerId; })) === null || _a === void 0 ? void 0 : _a.isCollapsed;
2445
+ var findItem = function (id) {
2446
+ // Iterate through each place
2447
+ for (var placeKey in items) {
2448
+ var place = items[placeKey];
2449
+ // Iterate through each group in the place
2450
+ for (var groupKey in place) {
2451
+ var group = place[groupKey];
2452
+ // Check if group is an array (to handle groups like group_18, group_82)
2453
+ if (Array.isArray(group)) {
2454
+ // Iterate through each task item in the group
2455
+ for (var _i = 0, group_1 = group; _i < group_1.length; _i++) {
2456
+ var item = group_1[_i];
2457
+ if (String(item.id) === String(id)) {
2458
+ return item; // Return the task item if found
2459
+ }
2460
+ }
2461
+ }
2462
+ }
2463
+ }
2464
+ };
2465
+ return (jsxs(GroupContainer, { groupData: ((_b = store.getAllGroupRecordsList) === null || _b === void 0 ? void 0 : _b.find(function (group) { return String(group.id) === extractedContainerId; })) || {}, style: {
2466
+ height: '100%',
2467
+ }, children: [isGroupCollapsed
2468
+ ? null
2469
+ : items[placeId][groupId]
2470
+ ? items[placeId][groupId].map(function (item, index) {
2471
+ var _a;
2472
+ var taskRecord = findItem(item.id);
2473
+ var bar = taskRecord === null || taskRecord === void 0 ? void 0 : taskRecord.task;
2474
+ if (!bar)
2475
+ return null;
2476
+ return (jsx(Item, { height: 40, handle: handle, renderItem: renderItem, children: columns.map(function (column, index) { return (jsx("div", { style: __assign({ width: getColumnsWidth[index], height: '100%', minWidth: column.minWidth, maxWidth: column.maxWidth, textAlign: column.align
2477
+ ? column.align
2478
+ : 'left' }, column.style), children: column.renderTaskCell ? column.renderTaskCell(bar) : bar[column.name] }, column.name)); }) }, ((_a = item === null || item === void 0 ? void 0 : item.task) === null || _a === void 0 ? void 0 : _a.id) + index));
2479
+ })
2480
+ : null, !isGroupCollapsed && (jsxs("button", { style: {
2481
+ width: '100%',
2482
+ justifyContent: 'flex-start',
2483
+ alignItems: 'center',
2484
+ padding: '12px 8px 11px',
2485
+ gap: '6px',
2486
+ display: 'flex',
2487
+ cursor: 'pointer',
2488
+ background: '#fff',
2489
+ border: 'none',
2490
+ borderBottom: '1px solid #E5E5E5',
2491
+ }, children: [jsxs("svg", { width: "12", height: "16", fill: "none", viewBox: "0 0 12 16", xmlns: "http://www.w3.org/2000/svg", children: [jsx("path", { fill: "#000", d: "M5.55556 4.44444C5.55556 4.19898 5.75454 4 6 4C6.24546 4 6.44444 4.19898 6.44444 4.44444V11.5556C6.44444 11.801 6.24546 12 6 12C5.75454 12 5.55556 11.801 5.55556 11.5556V4.44444Z" }), jsx("path", { fill: "#000", d: "M9.55556 7.55556C9.80102 7.55556 10 7.75454 10 8C10 8.24546 9.80102 8.44444 9.55556 8.44444L2.44444 8.44444C2.19898 8.44444 2 8.24546 2 8C2 7.75454 2.19898 7.55556 2.44444 7.55556L9.55556 7.55556Z" })] }), jsx("span", { style: {
2492
+ color: '#747474',
2493
+ fontSize: '12px',
2494
+ fontWeight: 400,
2495
+ fontStyle: 'normal',
2496
+ fontFamily: 'Wix Madefor Display',
2497
+ lineHeight: '16px',
2498
+ }, children: "\u0421\u043E\u0437\u0434\u0430\u0442\u044C \u0437\u0430\u0434\u0430\u0447\u0443" })] }))] }));
2499
+ }
2500
+ var DragGroupOverlay$1 = observer(DragGroupOverlay);
2501
+
2502
+ var PlaceContainer = React.forwardRef(function (props, ref) {
2503
+ var children = props.children, _a = props.columns, columns = _a === void 0 ? 1 : _a, handleProps = props.handleProps, handleToggleCollapse = props.handleToggleCollapse, placeData = props.placeData, placeholder = props.placeholder, style = props.style, onClick = props.onClick, otherProps = __rest(props, ["children", "columns", "handleProps", "handleToggleCollapse", "placeData", "placeholder", "style", "onClick"]);
2504
+ var store = useContext(context).store;
2505
+ var columnsWidth = store.getColumnsWidth;
2506
+ return (jsxs("div", __assign({}, otherProps, { ref: ref, style: __assign(__assign({}, style), { '--columns': columns }) }, handleProps, { tabIndex: onClick ? 0 : undefined, onClick: onClick, children: [jsx("div", { className: 'placeRow', children: store.columns.map(function (column, cellIndex) { return ((column.renderCollapsePlaceButton || column.renderPlaceCell) && (jsxs("div", { style: __assign({ width: columnsWidth[cellIndex], height: '100%', minWidth: column.minWidth, maxWidth: column.maxWidth, display: 'flex', textAlign: column.align ? column.align : 'left' }, column.style), onMouseDown: function (event) {
2507
+ if (column.isDraggableColumn === false) {
2508
+ event.stopPropagation();
2509
+ }
2510
+ }, children: [column.renderCollapsePlaceButton && (jsx("div", { onMouseDown: handleToggleCollapse, children: column.renderCollapsePlaceButton(placeData) })), column.renderPlaceCell && column.renderPlaceCell(placeData)] }, cellIndex))); }) }), placeholder ? children : jsx("ul", { style: { margin: 0, padding: 0 }, children: children })] })));
2511
+ });
2512
+
2513
+ function DragPlaceOverlay(props) {
2514
+ var _a, _b;
2515
+ var handle = props.handle, items = props.items, placeId = props.placeId, renderItem = props.renderItem;
2516
+ var store = useContext(context).store;
2517
+ var columns = store.columns, getColumnsWidth = store.getColumnsWidth;
2518
+ // const extractedContainerId = Number(placeId?.toString().replace('_group', ''))
2519
+ var findTaskItem = function (id) {
2520
+ // Iterate through each place
2521
+ for (var placeKey in items) {
2522
+ var place = items[placeKey];
2523
+ // Iterate through each group in the place
2524
+ for (var groupKey in place) {
2525
+ var group = place[groupKey];
2526
+ // Check if group is an array (to handle groups like group_18, group_82)
2527
+ if (Array.isArray(group)) {
2528
+ // Iterate through each task item in the group
2529
+ for (var _i = 0, group_1 = group; _i < group_1.length; _i++) {
2530
+ var item = group_1[_i];
2531
+ if (String(item.id) === String(id)) {
2532
+ return item; // Return the task item if found
2533
+ }
2534
+ }
2535
+ }
2536
+ }
2537
+ }
2538
+ };
2539
+ var extractedPlaceId = String(placeId).replace('_place', '');
2540
+ var isPlaceCollapsed = (_a = store.getRecordList.find(function (place) { return String(place.id) === extractedPlaceId; })) === null || _a === void 0 ? void 0 : _a.isCollapsed;
2541
+ return (jsx(PlaceContainer, { style: { height: '100%' }, placeData: store.getRecordList.find(function (place) { return String(place.id) === extractedPlaceId; }), children: !isPlaceCollapsed &&
2542
+ ((_b = Object.keys(items[placeId])) === null || _b === void 0 ? void 0 : _b.map(function (groupId, index) {
2543
+ var _a, _b;
2544
+ var extractedGroupId = String(groupId).replace('_group', '');
2545
+ var isGroupCollapsed = (_a = store.getAllGroupRecordsList.find(function (group) { return String(group.id) === extractedGroupId; })) === null || _a === void 0 ? void 0 : _a.isCollapsed;
2546
+ return (jsxs(GroupContainer, { groupData: ((_b = store.getAllGroupRecordsList) === null || _b === void 0 ? void 0 : _b.find(function (group) { return String(group.id) === extractedGroupId; })) || {}, style: {
2547
+ height: '100%',
2548
+ }, children: [isGroupCollapsed
2549
+ ? null
2550
+ : items[placeId][groupId]
2551
+ ? items[placeId][groupId].map(function (item, index) {
2552
+ var taskRecord = findTaskItem(item.id);
2553
+ var bar = taskRecord === null || taskRecord === void 0 ? void 0 : taskRecord.task;
2554
+ if (!bar)
2555
+ return null;
2556
+ return (jsx(Item, { height: 40, handle: handle, renderItem: renderItem, children: columns.map(function (column, index) { return (jsx("div", { style: __assign({ width: getColumnsWidth[index], height: '100%', minWidth: column.minWidth, maxWidth: column.maxWidth, textAlign: column.align
2557
+ ? column.align
2558
+ : 'left' }, column.style), children: column.renderTaskCell
2559
+ ? column.renderTaskCell(bar)
2560
+ : bar[column.name] }, column.name)); }) }, (item === null || item === void 0 ? void 0 : item.name_short) + index));
2561
+ })
2562
+ : null, !isGroupCollapsed && (jsxs("button", { style: {
2563
+ width: '100%',
2564
+ justifyContent: 'flex-start',
2565
+ alignItems: 'center',
2566
+ padding: '12px 8px 11px',
2567
+ gap: '6px',
2568
+ display: 'flex',
2569
+ cursor: 'pointer',
2570
+ background: '#fff',
2571
+ border: 'none',
2572
+ borderBottom: '1px solid #E5E5E5',
2573
+ }, children: [jsxs("svg", { width: "12", height: "16", fill: "none", viewBox: "0 0 12 16", xmlns: "http://www.w3.org/2000/svg", children: [jsx("path", { fill: "#000", d: "M5.55556 4.44444C5.55556 4.19898 5.75454 4 6 4C6.24546 4 6.44444 4.19898 6.44444 4.44444V11.5556C6.44444 11.801 6.24546 12 6 12C5.75454 12 5.55556 11.801 5.55556 11.5556V4.44444Z" }), jsx("path", { fill: "#000", d: "M9.55556 7.55556C9.80102 7.55556 10 7.75454 10 8C10 8.24546 9.80102 8.44444 9.55556 8.44444L2.44444 8.44444C2.19898 8.44444 2 8.24546 2 8C2 7.75454 2.19898 7.55556 2.44444 7.55556L9.55556 7.55556Z" })] }), jsx("span", { style: {
2574
+ color: '#747474',
2575
+ fontSize: '12px',
2576
+ fontWeight: 400,
2577
+ fontStyle: 'normal',
2578
+ fontFamily: 'Wix Madefor Display',
2579
+ lineHeight: '16px',
2580
+ }, children: "\u0421\u043E\u0437\u0434\u0430\u0442\u044C \u0437\u0430\u0434\u0430\u0447\u0443" })] }))] }, index));
2581
+ })) }));
2582
+ }
2583
+ var DragPlaceOverlay$1 = observer(DragPlaceOverlay);
2584
+
2585
+ function DragTaskOverlay(props) {
2586
+ var handle = props.handle, itemId = props.itemId, items = props.items, renderItem = props.renderItem;
2587
+ var store = useContext(context).store;
2588
+ var columns = store.columns, getColumnsWidth = store.getColumnsWidth;
2589
+ var findItem = function () {
2590
+ // Iterate through each place
2591
+ for (var placeKey in items) {
2592
+ var place = items[placeKey];
2593
+ // Iterate through each group in the place
2594
+ for (var groupKey in place) {
2595
+ var group = place[groupKey];
2596
+ // Check if group is an array (to handle groups like group_18, group_82)
2597
+ if (Array.isArray(group)) {
2598
+ // Iterate through each task item in the group
2599
+ for (var _i = 0, group_1 = group; _i < group_1.length; _i++) {
2600
+ var item = group_1[_i];
2601
+ if (String(item.id) === String(itemId)) {
2602
+ return item; // Return the task item if found
2603
+ }
2604
+ }
2605
+ }
2606
+ }
2607
+ }
2608
+ };
2609
+ var taskRecord = findItem();
2610
+ var bar = taskRecord === null || taskRecord === void 0 ? void 0 : taskRecord.task;
2611
+ if (!bar)
2612
+ return null;
2613
+ // movable element: task info
2614
+ return (jsx(Item, { height: 40, handle: handle, renderItem: renderItem, style: { height: '100%' }, children: columns.map(function (column, index) { return (jsx("div", { style: __assign({ width: getColumnsWidth[index], minWidth: column.minWidth, maxWidth: column.maxWidth, textAlign: column.align ? column.align : 'left' }, column.style), children: column.renderTaskCell ? column.renderTaskCell(bar) : jsx("span", { children: bar[column.name] }) }, column.name)); }) }));
2615
+ }
2616
+ var DragTaskOverlay$1 = observer(DragTaskOverlay);
2617
+
2618
+ var animateLayoutChanges$1 = function (args) {
2619
+ return defaultAnimateLayoutChanges(__assign(__assign({}, args), { wasDragging: true }));
2620
+ };
2621
+ function SortableContainer(props) {
2622
+ var id = props.id, children = props.children, disabled = props.disabled, groupData = props.groupData, items = props.items, style = props.style, toggleCollapseGroup = props.toggleCollapseGroup, groupContainerProps = __rest(props, ["id", "children", "disabled", "groupData", "items", "style", "toggleCollapseGroup"]);
2623
+ var _a = useSortable({
2624
+ id: id,
2625
+ animateLayoutChanges: animateLayoutChanges$1,
2626
+ data: { children: items, type: 'container' },
2627
+ }), transform = _a.transform, isDragging = _a.isDragging, attributes = _a.attributes, listeners = _a.listeners, setNodeRef = _a.setNodeRef, transition = _a.transition;
2628
+ // TODO: pass { ...attributes } and { ...listeners } without memoization
2629
+ var handleProps = useMemo(function () { return (__assign(__assign({}, attributes), listeners)); }, [attributes, listeners]);
2630
+ var handleToggleCollapse = useCallback(function () { return toggleCollapseGroup && toggleCollapseGroup(id); }, [id, toggleCollapseGroup]);
2631
+ return (jsx(GroupContainer, __assign({ ref: disabled ? undefined : setNodeRef, groupData: groupData, handleProps: handleProps, handleToggleCollapse: handleToggleCollapse,
2632
+ // TODO: is need to memoize object with styles? or memoize "SortableContainer" is better way?
2633
+ style: __assign(__assign({}, style), { opacity: isDragging ? 0.5 : undefined, transform: CSS.Translate.toString(transform), transition: transition }) }, groupContainerProps, { children: children })));
2634
+ }
2635
+
2636
+ function SortableItem(props) {
2637
+ var taskRecord = props.taskRecord, disabled = props.disabled, id = props.id, index = props.index, handle = props.handle, renderItem = props.renderItem, wrapperStyle = props.wrapperStyle, children = props.children, onContextMenu = props.onContextMenu;
2638
+ // prettier-ignore
2639
+ var _a = useSortable({ id: id }), setNodeRef = _a.setNodeRef, setActivatorNodeRef = _a.setActivatorNodeRef, listeners = _a.listeners, isSorting = _a.isSorting, transform = _a.transform, transition = _a.transition;
2640
+ var customListeners = useMemo(function () {
2641
+ if (onContextMenu) {
2642
+ listeners.onContextMenu = function (event) { return onContextMenu(taskRecord, event); };
2643
+ }
2644
+ return listeners;
2645
+ }, [taskRecord, listeners, onContextMenu]);
2646
+ return (jsx(Item, { handle: handle, handleProps: handle ? { ref: setActivatorNodeRef } : undefined, height: 40, index: index, listeners: customListeners, ref: disabled ? undefined : setNodeRef, renderItem: renderItem, sorting: isSorting, transform: transform, transition: transition, wrapperStyle: wrapperStyle({ index: index }), children: children }));
2647
+ }
2648
+
2649
+ var animateLayoutChanges = function (args) {
2650
+ return defaultAnimateLayoutChanges(__assign(__assign({}, args), { wasDragging: true }));
2651
+ };
2652
+ var SortablePlace = observer(function SortablePlace(props) {
2653
+ var id = props.id, children = props.children, disabled = props.disabled, items = props.items, placeData = props.placeData, style = props.style, toggleCollapsePlace = props.toggleCollapsePlace, placeContainerProps = __rest(props, ["id", "children", "disabled", "items", "placeData", "style", "toggleCollapsePlace"]);
2654
+ var _a = useSortable({
2655
+ id: id,
2656
+ animateLayoutChanges: animateLayoutChanges,
2657
+ data: { children: items, type: 'container' },
2658
+ }), transform = _a.transform, isDragging = _a.isDragging, attributes = _a.attributes, listeners = _a.listeners, setNodeRef = _a.setNodeRef, transition = _a.transition;
2659
+ // TODO: pass { ...attributes } and { ...listeners } without memoization
2660
+ var handleProps = useMemo(function () { return (__assign(__assign({}, attributes), listeners)); }, [attributes, listeners]);
2661
+ var handleToggleCollapsePlace = useCallback(function () { return toggleCollapsePlace && toggleCollapsePlace(placeData.id); }, [toggleCollapsePlace, placeData]);
2662
+ return (jsx(PlaceContainer, __assign({ ref: disabled ? undefined : setNodeRef, handleProps: handleProps, handleToggleCollapse: handleToggleCollapsePlace, placeData: placeData,
2663
+ // TODO: is need to memoize object with styles? or memoize "SortableContainer" is better way?
2664
+ style: __assign(__assign({}, style), { opacity: isDragging ? 0.5 : undefined, transform: CSS.Translate.toString(transform), transition: transition }) }, placeContainerProps, { children: children })));
2665
+ });
2666
+
2667
+ var dropAnimation = {
2668
+ sideEffects: defaultDropAnimationSideEffects({
2669
+ styles: {
2670
+ active: {
2671
+ opacity: '0.5',
2672
+ },
2673
+ },
2674
+ }),
2675
+ };
2676
+ var PLACEHOLDER_ID = 'placeholder';
2677
+ var extractIdFromKey = function (key, postfix_to_remove) {
2678
+ return String(key).replace(postfix_to_remove, '');
2679
+ };
2680
+ var MultipleContainers = observer(function MultipleContainers(props) {
2681
+ var _this = this;
2682
+ var _a = props.adjustScale, adjustScale = _a === void 0 ? false : _a, cancelDrop = props.cancelDrop, containerStyle = props.containerStyle, _b = props.handle, handle = _b === void 0 ? false : _b, initialPlacesData = props.initialPlacesData, modifiers = props.modifiers, moveTaskToAnotherGroup = props.moveTaskToAnotherGroup, renderItem = props.renderItem, _c = props.strategy, strategy = _c === void 0 ? verticalListSortingStrategy : _c, updateGroupsSorting = props.updateGroupsSorting, updatePlacesSorting = props.updatePlacesSorting, updateTasksSorting = props.updateTasksSorting, _d = props.vertical, vertical = _d === void 0 ? true : _d, _e = props.wrapperStyle, wrapperStyle = _e === void 0 ? function () { return ({}); } : _e;
2683
+ var _f = useTasksProps(), tableBefore = _f.tableBefore, onDeleteTask = _f.onDeleteTask;
2684
+ var _g = useContext(context), store = _g.store, onClickTaskItem = _g.onClickTaskItem, onDoubleClickTaskItem = _g.onDoubleClickTaskItem;
2685
+ var columns = store.columns, getColumnsWidth = store.getColumnsWidth;
2686
+ var sensors = useSensors(useSensor(MouseSensor, {
2687
+ activationConstraint: {
2688
+ distance: 10,
2689
+ },
2690
+ }), useSensor(TouchSensor));
2691
+ // const lastOverId = useRef<UniqueIdentifier | null>(null)
2692
+ var recentlyMovedToNewContainer = useRef(false);
2693
+ var containerRef = useRef();
2694
+ var _h = useState(initialPlacesData), items = _h[0], setItems = _h[1];
2695
+ // nested DnD states
2696
+ var _j = useState(function () {
2697
+ return Object.values(items).map(function (group) { return Object.keys(group); });
2698
+ }), groupContainersList = _j[0], setGroupContainersList = _j[1];
2699
+ var _k = useState(function () {
2700
+ return Object.keys(items);
2701
+ }), placeContainersList = _k[0], setPlaceContainersList = _k[1];
2702
+ var _l = useState(null), activeId = _l[0], setActiveId = _l[1];
2703
+ // States for storing moved tasks/groups/places data and update it in "onDragEnd" function
2704
+ // P.S. it's impossible to update the task data in "onDragEnd" without this state because of the nature of the function
2705
+ var _m = useState(null), movedTaskData = _m[0], setMovedTaskData = _m[1];
2706
+ var _o = useState(null), movedGroupData = _o[0], setMovedGroupData = _o[1];
2707
+ var _p = useState(null), movedPlaceData = _p[0], setMovedPlaceData = _p[1];
2708
+ var _q = useState(null), clonedItems = _q[0], setClonedItems = _q[1];
2709
+ var isSortingContainer = activeId
2710
+ ? groupContainersList.includes(activeId)
2711
+ : false;
2712
+ var activeContainerKind = useMemo(function () {
2713
+ if (placeContainersList.includes(activeId)) {
2714
+ return 'place';
2715
+ }
2716
+ if (groupContainersList.flat(5).includes(activeId)) {
2717
+ return 'group';
2718
+ }
2719
+ return 'task';
2720
+ }, [activeId, groupContainersList, placeContainersList]);
2721
+ useMemo(function () {
2722
+ return [
2723
+ {
2724
+ key: 'deleteTask',
2725
+ label: 'Удалить задачу',
2726
+ onClick: onDeleteTask,
2727
+ },
2728
+ ];
2729
+ }, [onDeleteTask]);
2730
+ /**
2731
+ * Custom collision detection strategy optimized for multiple containers
2732
+ *
2733
+ * - First, find any droppable containers intersecting with the pointer.
2734
+ * - If there are none, find intersecting containers with the active draggable.
2735
+ * - If there are no intersecting containers, return the last matched intersection
2736
+ *
2737
+ */
2738
+ // const collisionDetectionStrategy: CollisionDetection = useCallback(
2739
+ // (args) => {
2740
+ // if (activeId && activeId in items) {
2741
+ // return closestCenter({
2742
+ // ...args,
2743
+ // droppableContainers: args.droppableContainers.filter(
2744
+ // (container) => container.id in items,
2745
+ // ),
2746
+ // })
2747
+ // }
2748
+ // const pointerIntersections = pointerWithin(args)
2749
+ // const intersections = pointerIntersections.length > 0 ? pointerIntersections : rectIntersection(args)
2750
+ // let overId = getFirstCollision(intersections, 'id')
2751
+ // if (overId != null) {
2752
+ // if (overId in items) {
2753
+ // const containerItems = Object.values(items[overId])
2754
+ // if (containerItems.length > 0) {
2755
+ // overId = closestCenter({
2756
+ // ...args,
2757
+ // droppableContainers: args.droppableContainers.filter(
2758
+ // (container) =>
2759
+ // container.id !== overId && containerItems[container.id] !== undefined,
2760
+ // ),
2761
+ // })[0]?.id
2762
+ // }
2763
+ // }
2764
+ // lastOverId.current = overId
2765
+ // return [{ id: overId }]
2766
+ // }
2767
+ // if (recentlyMovedToNewContainer.current) {
2768
+ // lastOverId.current = activeId
2769
+ // }
2770
+ // return lastOverId.current ? [{ id: lastOverId.current }] : []
2771
+ // },
2772
+ // [activeId, items, lastOverId, recentlyMovedToNewContainer, setItems],
2773
+ // )
2774
+ var findContainer = useCallback(function (searchId, iterableItems) {
2775
+ if (iterableItems === void 0) { iterableItems = items; }
2776
+ // Check if the input is a place ID
2777
+ if (typeof searchId === 'string' && iterableItems[searchId]) {
2778
+ return searchId;
2779
+ }
2780
+ // Traverse through places and groups to find group ID or task ID
2781
+ for (var place_id in iterableItems) {
2782
+ for (var group_id in iterableItems[place_id]) {
2783
+ if (group_id === searchId) {
2784
+ return place_id; // Return group if group ID matches
2785
+ }
2786
+ var tasks = iterableItems[place_id][group_id].length > 0
2787
+ ? iterableItems[place_id][group_id]
2788
+ : [];
2789
+ for (var _i = 0, tasks_1 = tasks; _i < tasks_1.length; _i++) {
2790
+ var task = tasks_1[_i];
2791
+ if (String(task.id) === String(searchId)) {
2792
+ return group_id;
2793
+ }
2794
+ }
2795
+ }
2796
+ }
2797
+ // Return undefined if no match is found
2798
+ return undefined;
2799
+ }, [items]);
2800
+ var getIndex = useCallback(function (id) {
2801
+ var container = findContainer(id);
2802
+ if (!container) {
2803
+ return -1;
2804
+ }
2805
+ var index = Object.values(items)
2806
+ .map(function (groups) { return Object.keys(groups); })
2807
+ .flat(2)
2808
+ .indexOf(container);
2809
+ return index;
2810
+ }, [findContainer, items]);
2811
+ var handleDragStart = useCallback(function (params) {
2812
+ var active = params.active;
2813
+ setActiveId(active.id);
2814
+ setClonedItems(items);
2815
+ }, [items]);
2816
+ // TODO: Make better name, not "Div"
2817
+ // Quick decision for fix double click on task(or group) item.
2818
+ // Old way - is check by timeout two click in drag start... dear god.
2819
+ var onClickTaskItemDiv = useCallback(function (targetTaskRecordItem) {
2820
+ if (onClickTaskItem) {
2821
+ var allGroupRecordsList = store.getAllGroupRecordsList;
2822
+ var targetTaskGroupItem = allGroupRecordsList.find(function (groupItem) {
2823
+ var groupTaskRecordItem = groupItem.tasks.some(function (taskRecordItem) {
2824
+ return String(taskRecordItem.id) === String(targetTaskRecordItem.id);
2825
+ });
2826
+ return groupTaskRecordItem;
2827
+ });
2828
+ // @ts-expect-error
2829
+ onClickTaskItem(targetTaskRecordItem.id, targetTaskGroupItem === null || targetTaskGroupItem === void 0 ? void 0 : targetTaskGroupItem.id);
2830
+ }
2831
+ // "store.getAllGroupRecordsList" is observable property,
2832
+ // no need to depend in this case, but "store" is memoized instance of class
2833
+ }, [store, onClickTaskItem]);
2834
+ var onDoubleClickTaskItemDiv = useCallback(function (targetTaskRecordItem) {
2835
+ if (onDoubleClickTaskItem) {
2836
+ var allGroupRecordsList = store.getAllGroupRecordsList;
2837
+ var targetTaskGroupItem = allGroupRecordsList.find(function (groupItem) {
2838
+ var groupTaskRecordItem = groupItem.tasks.some(function (taskRecordItem) {
2839
+ return String(taskRecordItem.id) === String(targetTaskRecordItem.id);
2840
+ });
2841
+ return groupTaskRecordItem;
2842
+ });
2843
+ onDoubleClickTaskItem(targetTaskRecordItem.id, targetTaskGroupItem === null || targetTaskGroupItem === void 0 ? void 0 : targetTaskGroupItem.id);
2844
+ }
2845
+ // "store.getAllGroupRecordsList" is observable property,
2846
+ // no need to depend in this case, but "store" is memoized instance of class
2847
+ }, [store, onDoubleClickTaskItem]);
2848
+ // Function for move places according to the new sorting (is used onDragOver)
2849
+ var movePlaces = useCallback(function (activeId, overId) {
2850
+ var activeIndex = placeContainersList.indexOf(activeId);
2851
+ var overIndex = placeContainersList.indexOf(overId);
2852
+ var orderArray = arrayMove(placeContainersList, activeIndex, overIndex).map(function (placeItem, index) { return ({
2853
+ id: extractIdFromKey(placeItem, '_place'),
2854
+ sort: index,
2855
+ }); });
2856
+ setPlaceContainersList(function (places) {
2857
+ return arrayMove(places, activeIndex, overIndex);
2858
+ });
2859
+ setGroupContainersList(function (containers) {
2860
+ return arrayMove(containers, activeIndex, overIndex);
2861
+ });
2862
+ var updatedPlacesList = store.getRecordList.map(function (placeItem) {
2863
+ var placeSort = orderArray.find(function (item) { return String(item.id) === String(placeItem.id); }).sort;
2864
+ return __assign(__assign({}, placeItem), { sort: placeSort });
2865
+ });
2866
+ setMovedPlaceData(updatedPlacesList);
2867
+ },
2868
+ // "store.getRecordList" is observable property,
2869
+ // no need to depend in this case, but "store" is memoized instance of class
2870
+ [store, placeContainersList]);
2871
+ // Function for move groups according to the new sorting (is used onDragOver)
2872
+ var moveGroups = useCallback(function (active, overId) {
2873
+ var _a;
2874
+ var activeContainerId = findContainer(active.id);
2875
+ var overContainerId = findContainer(overId);
2876
+ // Prevent dragging groups between places, groups should be dragged only within the same place(!)
2877
+ if (activeContainerId !== overContainerId) {
2878
+ return;
2879
+ }
2880
+ if (activeContainerId && overContainerId) {
2881
+ var groupsContainer = groupContainersList
2882
+ .filter(function (groupList) {
2883
+ return groupList.includes(active.id);
2884
+ })
2885
+ .flat();
2886
+ var activeIndex = groupContainersList
2887
+ .filter(function (groupList) {
2888
+ return groupList.includes(active.id);
2889
+ })
2890
+ .flat()
2891
+ .indexOf(active.id);
2892
+ var overIndex = groupContainersList
2893
+ .filter(function (groupList) { return groupList.includes(overId); })
2894
+ .flat()
2895
+ .indexOf(overId);
2896
+ if (groupsContainer && activeIndex && overIndex) {
2897
+ var originalPlace = store.data.find(function (place) {
2898
+ return String(place.id) ===
2899
+ extractIdFromKey(activeContainerId, '_place');
2900
+ });
2901
+ if ((_a = originalPlace === null || originalPlace === void 0 ? void 0 : originalPlace.groups) === null || _a === void 0 ? void 0 : _a.length) {
2902
+ var updatedContainer_1 = arrayMove(groupsContainer, activeIndex, overIndex);
2903
+ var movedGroupsList = sortBy(toJS(originalPlace.groups), function (groupItem) {
2904
+ var newIndex = updatedContainer_1.findIndex(function (containerId) {
2905
+ return String(groupItem.id) ===
2906
+ extractIdFromKey(containerId, '_group');
2907
+ });
2908
+ return newIndex;
2909
+ });
2910
+ setMovedGroupData({
2911
+ changedGroupId: extractIdFromKey(active.id, '_group'),
2912
+ newSortValue: overIndex,
2913
+ placeId: extractIdFromKey(activeContainerId, '_place'),
2914
+ updatedGroupsList: movedGroupsList.map(function (group, index) { return (__assign(__assign({}, group), { sort: index })); }),
2915
+ // updatedGroupsList: arrayMove(originalPlace.groups, activeIndex, overIndex).map(
2916
+ // (group: iTasksGroup, index: number) => ({ ...group, sort: index }),
2917
+ // ),
2918
+ });
2919
+ setGroupContainersList(function (containers) {
2920
+ var newState = containers.map(function (container) {
2921
+ return container.includes(active.id) ? updatedContainer_1 : container;
2922
+ });
2923
+ return newState;
2924
+ });
2925
+ }
2926
+ }
2927
+ }
2928
+ },
2929
+ // "store.data" is observable property,
2930
+ // no need to depend in this case, but "store" is memoized instance of class
2931
+ [store, findContainer, groupContainersList]);
2932
+ // function for move tasks according to the new sorting (is used onDragOver)
2933
+ var moveTasks = useCallback(function (active, over) {
2934
+ var activeContainer = findContainer(active.id);
2935
+ var overContainer = findContainer(over.id);
2936
+ if (activeContainer === overContainer) {
2937
+ var currentPlace_1 = findContainer(activeContainer);
2938
+ // TODO: check if we can use indexes from dnd-kit
2939
+ // const origActiveIndex = active.data.current.sortable.index
2940
+ // const origOverIndex = over.data.current.sortable.index
2941
+ var activeIndex = items[currentPlace_1][activeContainer]
2942
+ .map(function (taskRecord) { return taskRecord.id; })
2943
+ .indexOf(active.id);
2944
+ var overIndex = items[currentPlace_1][activeContainer]
2945
+ .map(function (taskRecord) { return taskRecord.id; })
2946
+ .indexOf(over.id);
2947
+ var updatedGroupTasks_1 = arrayMove(items[currentPlace_1][activeContainer], activeIndex, overIndex);
2948
+ setItems(function (items) {
2949
+ var _a, _b;
2950
+ return (__assign(__assign({}, items), (_a = {}, _a[currentPlace_1] = __assign(__assign({}, items[currentPlace_1]), (_b = {}, _b[activeContainer] = updatedGroupTasks_1, _b)), _a)));
2951
+ });
2952
+ }
2953
+ }, [items, findContainer]);
2954
+ var onMoveTaskToAnotherGroup = useCallback(function (activeId, overId) {
2955
+ var _a, _b;
2956
+ var _c;
2957
+ // "active.id" is a task, so find its group
2958
+ var activeGroupId = findContainer(activeId);
2959
+ // "overId" is a group, so simply assign it to "overGroupId"
2960
+ var overGroupId = overId;
2961
+ // Find common place for active and over groups
2962
+ var commonPlaceId = findContainer(activeGroupId);
2963
+ if (findContainer(activeGroupId) !== findContainer(overGroupId)) {
2964
+ return;
2965
+ }
2966
+ // validate that the task is not moved to the same group
2967
+ if (activeGroupId === overGroupId) {
2968
+ return;
2969
+ }
2970
+ var activeItems = items[commonPlaceId][activeGroupId];
2971
+ var activeIndex = activeItems
2972
+ .map(function (taskRecord) { return taskRecord.id; })
2973
+ .indexOf(activeId);
2974
+ recentlyMovedToNewContainer.current = true;
2975
+ var extractedOverGroupId = extractIdFromKey(overGroupId, '_group');
2976
+ var isOverGroupCollapsed = (_c = store.getAllGroupRecordsList.find(function (group) { return String(group.id) === extractedOverGroupId; })) === null || _c === void 0 ? void 0 : _c.isCollapsed;
2977
+ if (isOverGroupCollapsed) {
2978
+ return;
2979
+ }
2980
+ var updatedData = __assign(__assign({}, items), (_a = {}, _a[commonPlaceId] = __assign(__assign({}, items[commonPlaceId]), (_b = {}, _b[activeGroupId] = items[commonPlaceId][activeGroupId].filter(function (item) { return String(item.id) !== String(activeId); }), _b[overGroupId] = __spreadArray(__spreadArray([], items[commonPlaceId][overGroupId], true), [
2981
+ items[commonPlaceId][activeGroupId][activeIndex],
2982
+ ], false).filter(function (item, index, self) {
2983
+ return index === self.findIndex(function (t) { return String(t.id) === String(item.id); });
2984
+ }), _b)), _a));
2985
+ setMovedTaskData({
2986
+ movedTask: items[commonPlaceId][activeGroupId][activeIndex],
2987
+ newGroupId: extractIdFromKey(overGroupId, '_group'),
2988
+ oldGroupId: extractIdFromKey(activeGroupId, '_group'),
2989
+ placeId: extractIdFromKey(commonPlaceId, '_place'),
2990
+ updatedData: updatedData,
2991
+ });
2992
+ setItems(updatedData);
2993
+ },
2994
+ // "store.getAllGroupRecordsList" is observable property,
2995
+ // no need to depend in this case, but "store" is memoized instance of class
2996
+ [store, items, findContainer]);
2997
+ // This is UI-only(!) function for updating the sorting of the tasks / groups / places
2998
+ var onDragOver = useCallback(function (params) {
2999
+ var active = params.active, over = params.over;
3000
+ var overId = over === null || over === void 0 ? void 0 : over.id;
3001
+ if (!overId) {
3002
+ return;
3003
+ }
3004
+ if (String(active.id) === String(overId)) {
3005
+ return;
3006
+ }
3007
+ if (String(active.id) === String(PLACEHOLDER_ID)) {
3008
+ return;
3009
+ }
3010
+ var isDragPlaceItem = active.id.toString().includes('_place');
3011
+ var isDragGroupItem = active.id.toString().includes('_group');
3012
+ var isDragTaskItem = !isDragPlaceItem && !isDragGroupItem;
3013
+ var isOverPlaceItem = overId.toString().includes('_place');
3014
+ var isOverGroupItem = overId.toString().includes('_group');
3015
+ var isOverTaskItem = !isOverPlaceItem && !isOverGroupItem;
3016
+ if (isDragPlaceItem) {
3017
+ // Case of dragging a place
3018
+ movePlaces(active.id, overId);
3019
+ return;
3020
+ }
3021
+ // Check if the active and over items are groups
3022
+ var isGroupsDraggingCase = isDragGroupItem && isOverGroupItem;
3023
+ // Case of dragging a group
3024
+ if (isGroupsDraggingCase) {
3025
+ moveGroups(active, overId);
3026
+ return;
3027
+ }
3028
+ // Case of dragging a task from one group to another
3029
+ if (isDragTaskItem && isOverGroupItem) {
3030
+ onMoveTaskToAnotherGroup(active.id, overId);
3031
+ }
3032
+ // Case of dragging a task
3033
+ if (isDragTaskItem && isOverTaskItem) {
3034
+ moveTasks(active, over);
3035
+ }
3036
+ }, [moveGroups, movePlaces, moveTasks, onMoveTaskToAnotherGroup]);
3037
+ // function for updating the sorting of the tasks / groups / places
3038
+ var onDragEnd = useCallback(function (params) { return __awaiter(_this, void 0, void 0, function () {
3039
+ var active, over, overId, isDragPlaceItem, isDragGroupItem, isDragTaskItem, isOverPlaceItem, isOverGroupItem, isOverTaskItem, activeGroupId, overGroupId, commonPlaceId, updatedGroupTasks;
3040
+ return __generator(this, function (_a) {
3041
+ switch (_a.label) {
3042
+ case 0:
3043
+ active = params.active, over = params.over;
3044
+ overId = over === null || over === void 0 ? void 0 : over.id;
3045
+ if (!overId) {
3046
+ return [2 /*return*/];
3047
+ }
3048
+ isDragPlaceItem = active.id.toString().includes('_place');
3049
+ isDragGroupItem = active.id.toString().includes('_group');
3050
+ isDragTaskItem = !isDragPlaceItem && !isDragGroupItem;
3051
+ isOverPlaceItem = overId.toString().includes('_place');
3052
+ isOverGroupItem = overId.toString().includes('_group');
3053
+ isOverTaskItem = !isOverPlaceItem && !isOverGroupItem;
3054
+ if (!movedTaskData) return [3 /*break*/, 2];
3055
+ return [4 /*yield*/, moveTaskToAnotherGroup(movedTaskData.updatedData, movedTaskData.newGroupId, movedTaskData.oldGroupId, movedTaskData.placeId, __assign(__assign({}, movedTaskData.movedTask), { sort: 0 }))];
3056
+ case 1:
3057
+ _a.sent();
3058
+ setMovedTaskData(null);
3059
+ _a.label = 2;
3060
+ case 2:
3061
+ if (!(isDragTaskItem && isOverTaskItem)) return [3 /*break*/, 4];
3062
+ activeGroupId = findContainer(active.id);
3063
+ overGroupId = findContainer(overId);
3064
+ commonPlaceId = findContainer(activeGroupId);
3065
+ if (activeGroupId !== overGroupId) {
3066
+ return [2 /*return*/];
3067
+ }
3068
+ updatedGroupTasks = items[commonPlaceId][activeGroupId].map(function (taskRecord, index) { return (__assign(__assign({}, taskRecord), { sort: index })); });
3069
+ return [4 /*yield*/, updateTasksSorting(updatedGroupTasks, extractIdFromKey(activeGroupId, '_group'))];
3070
+ case 3:
3071
+ _a.sent();
3072
+ return [2 /*return*/];
3073
+ case 4:
3074
+ // Case of dragging a group
3075
+ if (isDragGroupItem && overId && movedGroupData) {
3076
+ updateGroupsSorting && updateGroupsSorting(movedGroupData);
3077
+ }
3078
+ // Case of dragging a zone
3079
+ if ((movedPlaceData === null || movedPlaceData === void 0 ? void 0 : movedPlaceData.length) > 0) {
3080
+ updatePlacesSorting(movedPlaceData);
3081
+ }
3082
+ setMovedPlaceData(null);
3083
+ setMovedGroupData(null);
3084
+ return [2 /*return*/];
3085
+ }
3086
+ });
3087
+ }); }, [
3088
+ findContainer,
3089
+ items,
3090
+ moveTaskToAnotherGroup,
3091
+ movedGroupData,
3092
+ movedPlaceData,
3093
+ movedTaskData,
3094
+ updateGroupsSorting,
3095
+ updatePlacesSorting,
3096
+ updateTasksSorting,
3097
+ ]);
3098
+ var onDragCancel = useCallback(function () {
3099
+ /** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3100
+ * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
3101
+ * TODO: Think about another way to "reset items". DANGEROUS PLACE.
3102
+ * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
3103
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3104
+ */
3105
+ if (clonedItems) {
3106
+ // Reset items to their original state in case items have been
3107
+ // dragged across containers
3108
+ setItems(clonedItems);
3109
+ }
3110
+ setActiveId(null);
3111
+ setClonedItems(null);
3112
+ setMovedTaskData(null);
3113
+ }, []);
3114
+ var handleCreateNewTask = useCallback(function (groupId) {
3115
+ var _a;
3116
+ var _b;
3117
+ var newTaskPlaceIndex = store.data.findIndex(function (place) {
3118
+ return place.groups
3119
+ .map(function (group) { return String(group.id); })
3120
+ .includes(String(groupId));
3121
+ });
3122
+ var newTaskPlace = store.data[newTaskPlaceIndex];
3123
+ var newTaskGroup = newTaskPlace.groups.find(function (group) { return String(group.id) === String(groupId); });
3124
+ var newTaskSort = Math.max.apply(Math, __spreadArray(__spreadArray([], newTaskGroup.tasks.map(function (_a) {
3125
+ var sort = _a.sort;
3126
+ return sort;
3127
+ }), false), [0], false)) + 1;
3128
+ var newTaskPlaceKey = (newTaskPlace === null || newTaskPlace === void 0 ? void 0 : newTaskPlace.placeKey) || '';
3129
+ var newTaskPlaceId = (_b = newTaskPlace[newTaskPlaceKey]) === null || _b === void 0 ? void 0 : _b.id;
3130
+ if (!((newTaskPlace === null || newTaskPlace === void 0 ? void 0 : newTaskPlace.placeKey) &&
3131
+ newTaskGroup &&
3132
+ newTaskPlaceKey &&
3133
+ newTaskPlaceId)) {
3134
+ return;
3135
+ }
3136
+ var newTaskObject = (_a = {
3137
+ dt_begin: dayjs().format('YYYY-MM-DD HH:mm:ss'),
3138
+ dt_end: dayjs().add(3, 'hour').format('YYYY-MM-DD HH:mm:ss'),
3139
+ name: 'Новая задача',
3140
+ name_short: 'Новая задача'
3141
+ },
3142
+ _a[newTaskPlaceKey] = newTaskPlaceId,
3143
+ _a.sort = newTaskSort,
3144
+ _a);
3145
+ store.createNewTask(newTaskObject, groupId);
3146
+ }, [store]);
3147
+ var renderOverlay = useCallback(function () {
3148
+ switch (activeContainerKind) {
3149
+ case 'place':
3150
+ return (jsx(DragPlaceOverlay$1, { handle: handle, items: items, placeId: activeId, renderItem: renderItem }));
3151
+ case 'group':
3152
+ return (jsx(DragGroupOverlay$1, { groupId: activeId, handle: handle, items: items, placeId: findContainer(activeId), renderItem: renderItem }));
3153
+ case 'task':
3154
+ return (jsx(DragTaskOverlay$1, { handle: handle, itemId: activeId, items: items, renderItem: renderItem }));
3155
+ default:
3156
+ return null;
3157
+ }
3158
+ }, [activeContainerKind, activeId, findContainer, handle, items, renderItem]);
3159
+ var onContextMenuTaskItem = useCallback(function (taskRecord, event) {
3160
+ event.preventDefault();
3161
+ event.stopPropagation();
3162
+ var _a = store.contextMenuData, position = _a.position, item = _a.item;
3163
+ if (position || item) {
3164
+ store.update({ contextMenuData: { position: null, item: null } });
3165
+ }
3166
+ else {
3167
+ var clientX = event.clientX, clientY = event.clientY;
3168
+ var boundingClientRect = containerRef.current.getBoundingClientRect();
3169
+ store.update({
3170
+ contextMenuData: {
3171
+ position: {
3172
+ x: clientX - boundingClientRect.left,
3173
+ y: clientY - boundingClientRect.top,
3174
+ },
3175
+ item: taskRecord,
3176
+ },
3177
+ });
3178
+ }
3179
+ }, []);
3180
+ useEffect(function () {
3181
+ requestAnimationFrame(function () {
3182
+ recentlyMovedToNewContainer.current = false;
3183
+ });
3184
+ }, [items]);
3185
+ useEffect(function () {
3186
+ setGroupContainersList(Object.values(initialPlacesData).map(function (group) {
3187
+ return Object.keys(group);
3188
+ }));
3189
+ setItems(initialPlacesData);
3190
+ // setValidItems(initialPlacesData)
3191
+ setPlaceContainersList(Object.keys(initialPlacesData));
3192
+ }, [initialPlacesData]);
3193
+ return (jsxs(DndContext, { cancelDrop: cancelDrop, modifiers: modifiers, sensors: sensors, measuring: {
3194
+ droppable: {
3195
+ strategy: MeasuringStrategy.Always,
3196
+ },
3197
+ }, onDragCancel: onDragCancel, onDragEnd: onDragEnd, onDragOver: onDragOver, onDragStart: handleDragStart, children: [tableBefore, jsx("div", { ref: containerRef, style: {
3198
+ width: '100%',
3199
+ height: '100%',
3200
+ flexDirection: 'column',
3201
+ paddingBottom: '150px',
3202
+ overflow: 'hidden',
3203
+ display: 'flex',
3204
+ boxSizing: 'border-box',
3205
+ }, children: jsx(SortableContext, { items: __spreadArray(__spreadArray([], placeContainersList, true), [PLACEHOLDER_ID], false), strategy: vertical
3206
+ ? verticalListSortingStrategy
3207
+ : horizontalListSortingStrategy, children: placeContainersList.map(function (placeContainerId, placeIndex) {
3208
+ var _a, _b;
3209
+ var extractedPlaceId = extractIdFromKey(placeContainerId, '_place');
3210
+ var targetPlaceItem = store.getRecordList.find(function (place) { return String(place.id) === extractedPlaceId; });
3211
+ return (jsx(SortablePlace, { id: placeContainerId, items: placeContainersList, placeData: targetPlaceItem, toggleCollapsePlace: function () {
3212
+ return store.toggleCollapsePlace(extractedPlaceId);
3213
+ }, children: !targetPlaceItem.isCollapsed && (jsxs(SortableContext, { items: __spreadArray(__spreadArray([], groupContainersList, true), [PLACEHOLDER_ID], false), strategy: vertical
3214
+ ? verticalListSortingStrategy
3215
+ : horizontalListSortingStrategy, children: [(_a = groupContainersList[placeIndex]) === null || _a === void 0 ? void 0 : _a.map(function (containerId, index) {
3216
+ var _a, _b, _c;
3217
+ var extractedContainerId = extractIdFromKey(containerId, '_group');
3218
+ var taskArray = ((_b = (_a = items[placeContainerId]) === null || _a === void 0 ? void 0 : _a[containerId]) === null || _b === void 0 ? void 0 : _b.length) > 0
3219
+ ? items[placeContainerId][containerId]
3220
+ : [];
3221
+ var targetGroupItem = store.getAllGroupRecordsList.find(function (group) {
3222
+ return String(group.id) === extractedContainerId;
3223
+ });
3224
+ return (jsxs(SortableContainer, { groupData: targetGroupItem, id: containerId, items: placeContainersList, style: containerStyle, toggleCollapseGroup: function () {
3225
+ return store.toggleCollapseGroup(extractedContainerId);
3226
+ }, children: [jsx(SortableContext, { items: taskArray, strategy: strategy, children: !targetGroupItem.isCollapsed &&
3227
+ ((_c = items[placeContainerId][containerId]) === null || _c === void 0 ? void 0 : _c.map(function (taskRecord, itemIndex) {
3228
+ var bar = taskRecord === null || taskRecord === void 0 ? void 0 : taskRecord.task;
3229
+ if (!bar) {
3230
+ return null;
3231
+ }
3232
+ return (jsx(SortableItem, { containerId: containerId, disabled: isSortingContainer, getIndex: getIndex, handle: handle, id: taskRecord.id, index: itemIndex, renderItem: renderItem, taskRecord: taskRecord, wrapperStyle: wrapperStyle, onContextMenu: onContextMenuTaskItem, children: columns.map(function (column, cellIndex) { return (jsx("div", { style: __assign({ width: getColumnsWidth[cellIndex], height: '100%', minWidth: column.minWidth, maxWidth: column.maxWidth, textAlign: column.align
3233
+ ? column.align
3234
+ : 'left', borderRight: '1px solid #e5e5e5' }, column.style), onClick: function () {
3235
+ return onClickTaskItemDiv(taskRecord);
3236
+ }, onDoubleClick: function () {
3237
+ return onDoubleClickTaskItemDiv(taskRecord);
3238
+ }, children: column.renderTaskCell ? (column.renderTaskCell(bar)) : (jsx("span", { children: bar[column.name] })) }, column.name)); }) }, taskRecord.id));
3239
+ })) }), !targetGroupItem.isCollapsed && (jsxs("button", { style: {
3240
+ width: '100%',
3241
+ justifyContent: 'flex-start',
3242
+ alignItems: 'center',
3243
+ padding: '12px 8px 11px',
3244
+ gap: '6px',
3245
+ display: 'flex',
3246
+ cursor: 'pointer',
3247
+ background: '#fff',
3248
+ border: 'none',
3249
+ borderBottom: '1px solid #E5E5E5',
3250
+ },
3251
+ // @ts-expect-error
3252
+ onMouseDown: function (event) {
3253
+ event.stopPropagation();
3254
+ handleCreateNewTask(extractedContainerId);
3255
+ }, children: [jsxs("svg", { width: "12", height: "16", fill: "none", viewBox: "0 0 12 16", xmlns: "http://www.w3.org/2000/svg", children: [jsx("path", { fill: "#000", d: "M5.55556 4.44444C5.55556 4.19898 5.75454 4 6 4C6.24546 4 6.44444 4.19898 6.44444 4.44444V11.5556C6.44444 11.801 6.24546 12 6 12C5.75454 12 5.55556 11.801 5.55556 11.5556V4.44444Z" }), jsx("path", { fill: "#000", d: "M9.55556 7.55556C9.80102 7.55556 10 7.75454 10 8C10 8.24546 9.80102 8.44444 9.55556 8.44444L2.44444 8.44444C2.19898 8.44444 2 8.24546 2 8C2 7.75454 2.19898 7.55556 2.44444 7.55556L9.55556 7.55556Z" })] }), jsx("span", { style: {
3256
+ color: '#747474',
3257
+ fontSize: '12px',
3258
+ fontWeight: 400,
3259
+ fontStyle: 'normal',
3260
+ fontFamily: 'Wix Madefor Display',
3261
+ lineHeight: '16px',
3262
+ }, children: "\u0421\u043E\u0437\u0434\u0430\u0442\u044C \u0437\u0430\u0434\u0430\u0447\u0443" })] }))] }, "".concat(containerId, "_").concat(index)));
3263
+ }), !((_b = groupContainersList[placeIndex]) === null || _b === void 0 ? void 0 : _b.length) && (jsx("div", { children: "\u0417\u0434\u0435\u0441\u044C \u043F\u043E\u043A\u0430 \u043D\u0435\u0442 \u0433\u0440\u0443\u043F\u043F \u0434\u043B\u044F \u0437\u0430\u0434\u0430\u0447. \u0414\u043E\u0431\u0430\u0432\u044C\u0442\u0435 \u0433\u0440\u0443\u043F\u043F\u0443, \u0447\u0442\u043E\u0431\u044B \u043D\u0430\u0447\u0430\u0442\u044C \u0441\u043E\u0437\u0434\u0430\u0432\u0430\u0442\u044C \u0437\u0430\u0434\u0430\u0447\u0438." }))] })) }, placeContainerId));
3264
+ }) }) }), createPortal(jsx(DragOverlay, { adjustScale: adjustScale, dropAnimation: dropAnimation, style: {
3265
+ color: '#747474',
3266
+ fontSize: '12px',
3267
+ fontWeight: 400,
3268
+ fontStyle: 'normal',
3269
+ fontFamily: 'Wix Madefor Display',
3270
+ lineHeight: '16px',
3271
+ }, children: activeId ? renderOverlay() : null }), document.body)] }));
3272
+ });
3273
+
3274
+ var prettifyTasksData = function (data) {
3275
+ var output = {};
3276
+ data.forEach(function (place) {
3277
+ var prettifiedPlaceGroups = {};
3278
+ place.groups.forEach(function (group) {
3279
+ prettifiedPlaceGroups[group.id + '_group'] = group.tasks;
3280
+ });
3281
+ output[place.id + '_place'] = prettifiedPlaceGroups;
3282
+ });
3283
+ return output;
3284
+ };
3285
+ function Table() {
3286
+ var _this = this;
3287
+ var store = useContext(context).store;
3288
+ var tableData = useMemo(function () {
3289
+ // TODO: move sort to "setData" function. Also see "getBarList"
3290
+ var placesList = store.data.map(function (placeItem) {
3291
+ var groupsList = placeItem.record.groups.map(function (groupItem) {
3292
+ return __assign(__assign({}, groupItem), { tasks: sortBy(groupItem.tasks, 'sort') });
3293
+ });
3294
+ return __assign(__assign({}, placeItem.record), { groups: sortBy(groupsList, 'sort') });
3295
+ });
3296
+ // TODO: sort on store level
3297
+ return prettifyTasksData(sortBy(placesList, 'sort'));
3298
+ }, [store.data]);
3299
+ var handleMoveTaskToAnotherGroup = useCallback(function (updatedData, newGroupId, oldGroupId, placeId, movedTask) { return __awaiter(_this, void 0, void 0, function () {
3300
+ var updatedGroupsList, updatedOldGroup, updatedNewGroup, newGroupTasks, oldGroupTasks;
3301
+ var _a, _b;
3302
+ return __generator(this, function (_c) {
3303
+ switch (_c.label) {
3304
+ case 0:
3305
+ updatedGroupsList = __spreadArray([], store.data, true);
3306
+ updatedGroupsList.forEach(function (tasksGroup) {
3307
+ tasksGroup.tasks = updatedData[tasksGroup.record.id + '_group'];
3308
+ });
3309
+ updatedOldGroup = updatedGroupsList
3310
+ .map(function (place) { return place.groups; })
3311
+ .flat()
3312
+ .find(function (group) { return String(group.id) === String(oldGroupId); });
3313
+ updatedNewGroup = updatedGroupsList
3314
+ .map(function (place) { return place.groups; })
3315
+ .flat()
3316
+ .find(function (group) { return String(group.id) === String(newGroupId); });
3317
+ newGroupTasks = (_a = updatedData[placeId + '_place'][newGroupId + '_group']) !== null && _a !== void 0 ? _a : updatedNewGroup.tasks;
3318
+ oldGroupTasks = (_b = updatedData[placeId + '_place'][oldGroupId + '_group']) !== null && _b !== void 0 ? _b : updatedOldGroup.tasks;
3319
+ updatedOldGroup.tasks = oldGroupTasks;
3320
+ updatedNewGroup.tasks = newGroupTasks;
3321
+ return [4 /*yield*/, store.onMoveTaskToAnotherGroup(updatedNewGroup, updatedOldGroup, movedTask)];
3322
+ case 1:
3323
+ // Wait for the execution of store.moveTaskToAnotherGroup
3324
+ return [2 /*return*/, _c.sent()];
3325
+ }
3326
+ });
3327
+ }); }, [store.onMoveTaskToAnotherGroup, store.data]);
3328
+ // Function for updating the sorting of the task records
3329
+ var handleUpdateTaskRecordSorting = useCallback(function (updatedData, updatedGroupId) {
3330
+ var originalGroup = store.getAllGroupRecordsList.find(function (group) { return String(group.id) === String(updatedGroupId); });
3331
+ var updatedGroup = __assign(__assign({}, originalGroup), { tasks: updatedData });
3332
+ return store.onSortingChange(updatedGroup);
3333
+ }, [store]);
3334
+ // Function for updating the sorting of the groups(aka containers)
3335
+ var handleUpdateGroupsSorting = useCallback(function (updatedGroupsData) {
3336
+ store.updateOriginGroupsSorting(updatedGroupsData === null || updatedGroupsData === void 0 ? void 0 : updatedGroupsData.updatedGroupsList, updatedGroupsData === null || updatedGroupsData === void 0 ? void 0 : updatedGroupsData.placeId);
3337
+ }, [store]);
3338
+ // Function for updating the sorting of the groups(aka containers)
3339
+ var handleCreateNewTask = useCallback(function (newTaskData, groupId) {
3340
+ store.createNewTask(newTaskData, groupId);
3341
+ }, [store]);
3342
+ return (jsx(MultipleContainers, { createNewTask: handleCreateNewTask, initialPlacesData: tableData, moveTaskToAnotherGroup: handleMoveTaskToAnotherGroup, strategy: verticalListSortingStrategy, updateGroupsSorting: handleUpdateGroupsSorting, updatePlacesSorting: store.onPlaceSortingChange, updateTasksSorting: handleUpdateTaskRecordSorting }));
3343
+ }
3344
+ var Table$1 = observer(Table);
3345
+
3346
+ var TableBody = observer(function TableBody() {
3347
+ var store = useContext(context).store;
3348
+ var handleMouseMove = useCallback(function (event) {
3349
+ event.persist();
3350
+ store.handleMouseMove(event);
3351
+ }, [store]);
3352
+ var handleMouseLeave = useCallback(function () {
3353
+ store.handleMouseLeave();
3354
+ }, [store]);
3355
+ return (jsx("div", { style: {
3356
+ position: 'relative',
3357
+ width: store.tableWidth,
3358
+ height: store.bodyScrollHeight,
3359
+ }, onMouseLeave: handleMouseLeave, onMouseMove: handleMouseMove, children: store.getBarList.length ? (jsx(Table$1, {})) : (jsx("div", { style: {
3360
+ textAlign: 'center',
3361
+ color: ' rgba(0,0,0,0.65)',
3362
+ marginTop: 30,
3363
+ }, children: "No data" })) }));
3364
+ });
3365
+
3366
+ var TimeIndicator = function () {
3367
+ var _a;
3368
+ var store = useContext(context).store;
3369
+ var scrolling = store.scrolling, translateX = store.translateX, tableWidth = store.tableWidth, viewWidth = store.viewWidth, todayTranslateX = store.todayTranslateX, locale = store.locale;
3370
+ var type = todayTranslateX < translateX ? 'left' : 'right';
3371
+ var left = type === 'left' ? tableWidth : 'unset';
3372
+ var right = type === 'right' ? 111 : 'unset';
3373
+ var width = 'fit-content';
3374
+ var display = useMemo(function () {
3375
+ var isOverLeft = todayTranslateX < translateX;
3376
+ var isOverRight = todayTranslateX > translateX + viewWidth;
3377
+ return isOverLeft || isOverRight ? 'block' : 'block';
3378
+ }, [todayTranslateX, translateX, viewWidth]);
3379
+ var currentTimeLabel = useMemo(function () {
3380
+ var currentSight = store.sightConfig.type;
3381
+ switch (currentSight) {
3382
+ case 'hour':
3383
+ return locale.today;
3384
+ case 'day':
3385
+ return locale.today;
3386
+ case 'week':
3387
+ return 'Текущая';
3388
+ case 'month':
3389
+ return 'Текущий';
3390
+ default:
3391
+ return locale.today;
3392
+ }
3393
+ }, [store.sightConfig.type]);
3394
+ var handleClick = useCallback(function () {
3395
+ store.scrollToToday();
3396
+ }, [store.scrollToToday]);
3397
+ return (jsx("button", { className: classNames('gantt__time-indicator', (_a = {},
3398
+ _a["gantt__time-indicator-scrolling"] = scrolling,
3399
+ _a)), "data-role": "button", style: { left: left, right: right, display: display, width: width }, type: "button", onClick: handleClick, children: jsx("span", { className: "gantt__time-indicator-text", children: currentTimeLabel }) }));
3400
+ };
3401
+ var TimeIndicator$1 = observer(TimeIndicator);
3402
+
3403
+ var TableInterval = function () {
3404
+ var _a = useContext(context), store = _a.store, showBackToday = _a.showBackToday;
3405
+ var sightConfig = store.sightConfig, isToday = store.isToday, isCurrentHour = store.isCurrentHour;
3406
+ var majorList = store.getMajorList();
3407
+ var minorList = store.getMinorList();
3408
+ var handleResize = useCallback(function (_a) {
3409
+ var x = _a.x;
3410
+ store.handlePanMove(-x);
3411
+ }, [store]);
3412
+ var handleLeftResizeEnd = useCallback(function () {
3413
+ store.handlePanEnd();
3414
+ }, [store]);
3415
+ var getIsToday = useCallback(function (item) {
3416
+ var key = item.key;
3417
+ var type = sightConfig.type;
3418
+ return type === 'day' && isToday(key);
3419
+ }, [sightConfig, isToday]);
3420
+ var getIsCurrentHour = useCallback(function (item) {
3421
+ var key = item.key;
3422
+ var type = sightConfig.type;
3423
+ return type === 'hour' && isCurrentHour(key);
3424
+ }, [sightConfig, isCurrentHour]);
3425
+ return (jsx(DragResize$1, { defaultSize: {
3426
+ x: -store.translateX,
3427
+ width: 0,
3428
+ }, type: "move", onResize: handleResize, onResizeEnd: handleLeftResizeEnd, children: jsxs("div", { className: "gantt__table-interval", style: {
3429
+ left: store.tableWidth,
3430
+ width: store.viewWidth,
3431
+ }, children: [jsx("div", { className: "gantt__table-interval-label", children: showBackToday && jsx(TimeIndicator$1, {}) }), jsxs("div", { className: "gantt__table-interval-render-chunk", style: {
3432
+ transform: "translateX(-".concat(store.translateX, "px"),
3433
+ }, children: [majorList.map(function (item) { return (jsx("div", { className: "gantt__table-interval-major", style: { width: item.width, left: item.left }, children: jsx("div", { className: "gantt__table-interval-major-label", children: item.label }) }, item.key)); }), minorList.map(function (item) {
3434
+ var _a;
3435
+ return (jsx("div", { className: classNames("gantt__table-interval-minor", (_a = {},
3436
+ _a["gantt__table-interval-minor-today"] = getIsToday(item) || getIsCurrentHour(item),
3437
+ _a)), style: {
3438
+ width: item.width,
3439
+ left: item.left,
3440
+ background: item.isWeek ? '#D9D9D9' : null,
3441
+ }, children: jsx("div", { className: classNames("gantt__table-interval-minor-label"), children: item.label }) }, item.key));
3442
+ })] })] }) }));
3443
+ };
3444
+ var TableInterval$1 = observer(TableInterval);
3445
+
3446
+ var TableTask = function (props) {
3447
+ var store = useContext(context).store;
3448
+ var columns = store.columns, tableWidth = store.tableWidth;
3449
+ var width = tableWidth;
3450
+ var columnsWidth = store.getColumnsWidth;
3451
+ var children = props.children;
3452
+ return (jsx("div", { className: 'gantt__table-task', style: { width: width }, children: jsx("div", { className: 'gantt__table-task-row', children: columns.map(function (column, index) { return (jsxs("div", { className: 'gantt__table-task-cell', style: __assign({ width: columnsWidth[index], minWidth: column.minWidth, maxWidth: column.maxWidth, textAlign: column.align ? column.align : 'left', borderRight: column.borderRight }, column.style), children: [jsx("span", { className: 'gantt__table-task-cell-text', style: { justifyContent: column.justifyContent ? column.justifyContent : 'center' }, children: column.label }), children] }, column.name)); }) }) }));
3453
+ };
3454
+ var TableTask$1 = observer(TableTask);
3455
+
3456
+ var Body = function (_a) {
3457
+ var children = _a.children;
3458
+ var store = useContext(context).store;
3459
+ var reference = useRef(null);
3460
+ var size = useSize(reference);
3461
+ useEffect(function () {
3462
+ store.syncSize(size);
3463
+ }, [size, store]);
3464
+ return (jsx("div", { ref: reference, className: "gantt-body", style: { maxWidth: '100vw !important' }, children: children }));
3465
+ };
3466
+ var GanttComponent = function (props) {
3467
+ var isRestDay = props.isRestDay, _a = props.alwaysShowTaskBar, alwaysShowTaskBar = _a === void 0 ? true : _a, columns = props.columns, _b = props.customSights, customSights = _b === void 0 ? [] : _b, data = props.data, _c = props.dependencies, dependencies = _c === void 0 ? [] : _c, _d = props.disabled, disabled = _d === void 0 ? false : _d, _e = props.endDateKey, endDateKey = _e === void 0 ? 'dt_end' : _e, expandIcon = props.expandIcon, getBarColor = props.getBarColor, _f = props.hideTable, hideTable = _f === void 0 ? false : _f, innerRef = props.innerRef, _g = props.maxDateLimit, maxDateLimit = _g === void 0 ? null : _g, mediaUrl = props.mediaUrl, _h = props.minDateLimit, minDateLimit = _h === void 0 ? null : _h, renderBar = props.renderBar, renderBarThumb = props.renderBarThumb, renderGroupBar = props.renderGroupBar, renderInvalidBar = props.renderInvalidBar, renderLeftText = props.renderLeftText, renderRightText = props.renderRightText, _j = props.rowHeight, rowHeight = _j === void 0 ? ROW_HEIGHT : _j, _k = props.scrollTop, scrollTop = _k === void 0 ? true : _k, _l = props.showBackToday, showBackToday = _l === void 0 ? true : _l, _m = props.showUnitSwitch, showUnitSwitch = _m === void 0 ? true : _m, _o = props.startDateKey, startDateKey = _o === void 0 ? 'dt_begin' : _o, _p = props.tableCollapseAble, tableCollapseAble = _p === void 0 ? true : _p, _q = props.tableIndent, tableIndent = _q === void 0 ? TABLE_INDENT : _q, taskStatusesChoices = props.taskStatusesChoices, unit = props.unit, _r = props.onAddTaskAssignee, onAddTaskAssignee = _r === void 0 ? function () {
3468
+ return [];
3469
+ } : _r, onBarClick = props.onBarClick, onClickTaskItem = props.onClickTaskItem, _s = props.onCreateNewTask, onCreateNewTask = _s === void 0 ? function () {
3470
+ return [];
3471
+ } : _s; props.onDeleteTask; var onDoubleClickTaskItem = props.onDoubleClickTaskItem, onExpand = props.onExpand, _t = props.onGroupSortingChange, onGroupSortingChange = _t === void 0 ? function () {
3472
+ return [];
3473
+ } : _t, _u = props.onMoveTaskToAnotherGroup, onMoveTaskToAnotherGroup = _u === void 0 ? function () {
3474
+ return Promise.resolve(false);
3475
+ } : _u, _v = props.onPlaceSortingChange, onPlaceSortingChange = _v === void 0 ? function () {
3476
+ return [];
3477
+ } : _v, onRow = props.onRow, _w = props.onSortingChange, onSortingChange = _w === void 0 ? function () {
3478
+ return [];
3479
+ } : _w, onUpdate = props.onUpdate;
3480
+ var store = useMemo(function () {
3481
+ return new GanttStore({
3482
+ customSights: customSights,
3483
+ disabled: disabled,
3484
+ rowHeight: rowHeight,
3485
+ taskStatusesChoices: taskStatusesChoices,
3486
+ });
3487
+ }, [rowHeight]);
3488
+ useEffect(function () {
3489
+ store.setData(data, startDateKey, endDateKey);
3490
+ }, [data, endDateKey, startDateKey, store]);
3491
+ useEffect(function () {
3492
+ store.setColumns(columns);
3493
+ }, [columns, store]);
3494
+ useEffect(function () {
3495
+ store.setOnUpdate(onUpdate);
3496
+ }, [onUpdate, store]);
3497
+ useEffect(function () {
3498
+ store.setOnSortingChange(onSortingChange);
3499
+ }, [onSortingChange, store]);
3500
+ useEffect(function () {
3501
+ store.setOnGroupSortingChange(onGroupSortingChange);
3502
+ }, [onGroupSortingChange, store]);
3503
+ useEffect(function () {
3504
+ store.setOnPlaceSortingChange(onPlaceSortingChange);
3505
+ }, [onPlaceSortingChange, store]);
3506
+ useEffect(function () {
3507
+ store.setOnMoveTaskToAnotherGroup(onMoveTaskToAnotherGroup);
3508
+ }, [onMoveTaskToAnotherGroup, store]);
3509
+ useEffect(function () {
3510
+ store.setOnCreateNewTask(onCreateNewTask);
3511
+ }, [onCreateNewTask, store]);
3512
+ useEffect(function () {
3513
+ store.setOnAddTaskAssignee(onAddTaskAssignee);
3514
+ }, [onAddTaskAssignee, store]);
3515
+ useEffect(function () {
3516
+ store.setDependencies(dependencies);
3517
+ }, [dependencies, store]);
3518
+ useEffect(function () {
3519
+ store.setHideTable(hideTable);
3520
+ }, [hideTable]);
3521
+ useEffect(function () {
3522
+ if (isRestDay)
3523
+ store.setIsRestDay(isRestDay);
3524
+ }, [isRestDay, store]);
3525
+ useEffect(function () {
3526
+ if (unit)
3527
+ store.switchSight(unit);
3528
+ }, [unit, store]);
3529
+ useEffect(function () {
3530
+ if (minDateLimit)
3531
+ store.setMinDateLimit(minDateLimit);
3532
+ }, [minDateLimit, store]);
3533
+ useEffect(function () {
3534
+ if (maxDateLimit)
3535
+ store.setMaxDateLimit(maxDateLimit);
3536
+ }, [maxDateLimit, store]);
3537
+ useImperativeHandle(innerRef, function () { return ({
3538
+ backToday: function () { return store.scrollToToday(); },
3539
+ getWidthByDate: store.getWidthByDate,
3540
+ }); });
3541
+ var ContextValue = React.useMemo(function () { return ({
3542
+ alwaysShowTaskBar: alwaysShowTaskBar,
3543
+ barHeight: BAR_HEIGHT,
3544
+ expandIcon: expandIcon,
3545
+ getBarColor: getBarColor,
3546
+ hideTable: hideTable,
3547
+ mediaUrl: mediaUrl,
3548
+ renderBar: renderBar,
3549
+ renderBarThumb: renderBarThumb,
3550
+ renderGroupBar: renderGroupBar,
3551
+ renderInvalidBar: renderInvalidBar,
3552
+ renderLeftText: renderLeftText,
3553
+ renderRightText: renderRightText,
3554
+ scrollTop: scrollTop,
3555
+ showBackToday: showBackToday,
3556
+ showUnitSwitch: showUnitSwitch,
3557
+ store: store,
3558
+ tableCollapseAble: tableCollapseAble,
3559
+ tableIndent: tableIndent,
3560
+ onBarClick: onBarClick,
3561
+ onClickTaskItem: onClickTaskItem,
3562
+ onDoubleClickTaskItem: onDoubleClickTaskItem,
3563
+ onExpand: onExpand,
3564
+ onRow: onRow,
3565
+ }); }, [
3566
+ store,
3567
+ getBarColor,
3568
+ showBackToday,
3569
+ showUnitSwitch,
3570
+ onRow,
3571
+ tableIndent,
3572
+ expandIcon,
3573
+ renderBar,
3574
+ renderInvalidBar,
3575
+ renderGroupBar,
3576
+ onBarClick,
3577
+ onClickTaskItem,
3578
+ onDoubleClickTaskItem,
3579
+ tableCollapseAble,
3580
+ renderBarThumb,
3581
+ scrollTop,
3582
+ alwaysShowTaskBar,
3583
+ renderLeftText,
3584
+ renderRightText,
3585
+ mediaUrl,
3586
+ onExpand,
3587
+ hideTable,
3588
+ ]);
3589
+ return (jsx(context.Provider, { value: ContextValue, children: jsxs(Body, { children: [jsxs("header", { children: [showUnitSwitch && jsx(Header$1, {}), jsx(TableTask$1, {}), jsx(TableInterval$1, {})] }), jsxs("main", { ref: store.mainElementRef, onScroll: store.handleScroll, children: [!hideTable && (jsx(TasksPropsProvider, __assign({}, props, { children: jsx(TableBody, {}) }))), jsx(SelectionIndicator$1, {}), jsx(Chart$1, {})] }), !hideTable && jsx(Divider$1, {}), jsx(ScrollBar$1, {}), scrollTop && jsx(ScrollTop$1, {})] }) }));
3590
+ };
3591
+
3592
+ export { GanttComponent as default, ruRU };