react-big-schedule 8.0.0 → 9.0.0
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.
- package/README.md +20 -1129
- package/dist/calendar/Calendar.d.ts +28 -0
- package/dist/calendar/Calendar.js +95 -0
- package/dist/calendar/Toolbar.d.ts +18 -0
- package/dist/calendar/Toolbar.js +6 -0
- package/dist/calendar/recurrence.check.d.ts +1 -0
- package/dist/calendar/recurrence.check.js +49 -0
- package/dist/calendar/recurrence.d.ts +8 -0
- package/dist/calendar/recurrence.js +90 -0
- package/dist/calendar/timezone.d.ts +6 -0
- package/dist/calendar/timezone.js +14 -0
- package/dist/calendar/types.d.ts +187 -0
- package/dist/calendar/types.js +1 -0
- package/dist/calendar/useEventSources.d.ts +11 -0
- package/dist/calendar/useEventSources.js +89 -0
- package/dist/calendar/useRecurrence.d.ts +4 -0
- package/dist/calendar/useRecurrence.js +15 -0
- package/dist/calendar/utils.d.ts +38 -0
- package/dist/calendar/utils.js +143 -0
- package/dist/calendar/views/DayGridView.d.ts +3 -0
- package/dist/calendar/views/DayGridView.js +375 -0
- package/dist/calendar/views/ListView.d.ts +4 -0
- package/dist/calendar/views/ListView.js +56 -0
- package/dist/calendar/views/MultiMonthView.d.ts +4 -0
- package/dist/calendar/views/MultiMonthView.js +36 -0
- package/dist/calendar/views/TimeGridView.d.ts +3 -0
- package/dist/calendar/views/TimeGridView.js +334 -0
- package/dist/calendar/views/daygrid/DayCell.d.ts +19 -0
- package/dist/calendar/views/daygrid/DayCell.js +17 -0
- package/dist/calendar/views/daygrid/EventChip.d.ts +19 -0
- package/dist/calendar/views/daygrid/EventChip.js +40 -0
- package/dist/calendar/views/daygrid/layout.d.ts +30 -0
- package/dist/calendar/views/daygrid/layout.js +63 -0
- package/dist/calendar/views/list/bucket.d.ts +8 -0
- package/dist/calendar/views/list/bucket.js +37 -0
- package/dist/calendar/views/multimonth/Cell.d.ts +12 -0
- package/dist/calendar/views/multimonth/Cell.js +44 -0
- package/dist/calendar/views/multimonth/Continuous.d.ts +8 -0
- package/dist/calendar/views/multimonth/Continuous.js +28 -0
- package/dist/calendar/views/multimonth/MonthGrid.d.ts +10 -0
- package/dist/calendar/views/multimonth/MonthGrid.js +36 -0
- package/dist/calendar/views/multimonth/shared.d.ts +27 -0
- package/dist/calendar/views/multimonth/shared.js +40 -0
- package/dist/calendar/views/timegrid/DayColumn.d.ts +49 -0
- package/dist/calendar/views/timegrid/DayColumn.js +86 -0
- package/dist/calendar/views/timegrid/model.d.ts +55 -0
- package/dist/calendar/views/timegrid/model.js +102 -0
- package/dist/components/AddMore.d.ts +13 -0
- package/dist/components/AddMore.js +9 -42
- package/dist/components/AddMorePopover.d.ts +13 -0
- package/dist/components/AddMorePopover.js +24 -95
- package/dist/components/AgendaEventItem.d.ts +10 -0
- package/dist/components/AgendaEventItem.js +33 -81
- package/dist/components/AgendaResourceEvents.d.ts +10 -0
- package/dist/components/AgendaResourceEvents.js +38 -90
- package/dist/components/AgendaView.d.ts +9 -0
- package/dist/components/AgendaView.js +10 -69
- package/dist/components/BodyView.d.ts +11 -0
- package/dist/components/BodyView.js +36 -67
- package/dist/components/DnDContext.d.ts +48 -0
- package/dist/components/DnDContext.js +200 -221
- package/dist/components/DnDSource.d.ts +49 -0
- package/dist/components/DnDSource.js +125 -120
- package/dist/components/EventItem.d.ts +41 -0
- package/dist/components/EventItem.js +585 -787
- package/dist/components/EventItemPopover.d.ts +12 -0
- package/dist/components/EventItemPopover.js +19 -143
- package/dist/components/HeaderView.d.ts +14 -0
- package/dist/components/HeaderView.js +123 -186
- package/dist/components/ResourceEvents.d.ts +54 -0
- package/dist/components/ResourceEvents.js +534 -703
- package/dist/components/ResourceView.d.ts +26 -0
- package/dist/components/ResourceView.js +64 -184
- package/dist/components/SchedulerData.d.ts +136 -0
- package/dist/components/SchedulerData.js +1296 -1226
- package/dist/components/SchedulerHeader.d.ts +25 -0
- package/dist/components/SchedulerHeader.js +50 -150
- package/dist/components/SelectedArea.d.ts +8 -0
- package/dist/components/SelectedArea.js +11 -26
- package/dist/components/Summary.d.ts +11 -0
- package/dist/components/Summary.js +21 -50
- package/dist/components/WrapperFun.d.ts +2 -0
- package/dist/components/WrapperFun.js +5 -10
- package/dist/components/index.d.ts +44 -0
- package/dist/components/index.js +428 -654
- package/dist/components/ui/Icons.d.ts +8 -0
- package/dist/components/ui/Icons.js +7 -0
- package/dist/components/ui/MiniCalendar.d.ts +9 -0
- package/dist/components/ui/MiniCalendar.js +17 -0
- package/dist/components/ui/Popover.d.ts +13 -0
- package/dist/components/ui/Popover.js +80 -0
- package/dist/config/default.d.ts +36 -0
- package/dist/config/default.js +17 -26
- package/dist/config/i18n.d.ts +27 -0
- package/dist/config/i18n.js +21 -37
- package/dist/config/scheduler.d.ts +12 -0
- package/dist/config/scheduler.js +126 -119
- package/dist/css/style.css +2 -316
- package/dist/helper/behaviors.d.ts +14 -0
- package/dist/helper/behaviors.js +75 -75
- package/dist/helper/utility.d.ts +26 -0
- package/dist/helper/utility.js +23 -30
- package/dist/index.d.ts +6 -477
- package/dist/index.js +4 -2
- package/dist/sample-data/sample1.d.ts +11 -0
- package/dist/sample-data/sample1.js +427 -372
- package/dist/types.d.ts +267 -0
- package/dist/types.js +1 -0
- package/package.json +35 -26
|
@@ -1,229 +1,208 @@
|
|
|
1
1
|
import { CellUnit, DATETIME_FORMAT, DnDTypes, ViewType } from '../config/default';
|
|
2
2
|
import { getPos } from '../helper/utility';
|
|
3
3
|
export default class DnDContext {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
sources
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const initialPoint = monitor.getInitialClientOffset();
|
|
12
|
-
const initialLeftIndex = Math.floor((initialPoint.x - pos.x) / cellWidth);
|
|
13
|
-
const initialStart = resourceEvents.headerItems[initialLeftIndex].start;
|
|
14
|
-
let initialEnd = resourceEvents.headerItems[initialLeftIndex].end;
|
|
15
|
-
if (cellUnit !== CellUnit.Hour) {
|
|
16
|
-
const end = localeDayjs(new Date(initialStart)).hour(23).minute(59).second(59);
|
|
17
|
-
initialEnd = end.format(DATETIME_FORMAT);
|
|
4
|
+
sourceMap;
|
|
5
|
+
config;
|
|
6
|
+
constructor(sources) {
|
|
7
|
+
this.sourceMap = new Map();
|
|
8
|
+
sources.forEach(item => {
|
|
9
|
+
this.sourceMap.set(item.dndType, item);
|
|
10
|
+
});
|
|
18
11
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
extractInitialTimes = (monitor, pos, cellWidth, resourceEvents, cellUnit, localeDayjs) => {
|
|
13
|
+
// a drag is in progress, so the initial offset is set
|
|
14
|
+
const initialPoint = monitor.getInitialClientOffset();
|
|
15
|
+
const initialLeftIndex = Math.floor((initialPoint.x - pos.x) / cellWidth);
|
|
16
|
+
const initialStart = resourceEvents.headerItems[initialLeftIndex].start;
|
|
17
|
+
let initialEnd = resourceEvents.headerItems[initialLeftIndex].end;
|
|
18
|
+
if (cellUnit !== CellUnit.Hour) {
|
|
19
|
+
const end = localeDayjs(new Date(initialStart)).hour(23).minute(59).second(59);
|
|
20
|
+
initialEnd = end.format(DATETIME_FORMAT);
|
|
21
|
+
}
|
|
22
|
+
return { initialStart, initialEnd };
|
|
22
23
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const slotName = schedulerData.getSlotById(slotId)?.name;
|
|
50
|
-
return {
|
|
51
|
-
slotId,
|
|
52
|
-
slotName,
|
|
53
|
-
start: start.format(DATETIME_FORMAT),
|
|
54
|
-
end: end.format(DATETIME_FORMAT),
|
|
55
|
-
isVertical: true
|
|
24
|
+
// Vertical resource view: rows are time slots and columns are resources, so the pointer column picks the
|
|
25
|
+
// resource and the pointer row, relative to the row the event was grabbed in, shifts its time.
|
|
26
|
+
getVerticalMove = (props, monitor, component) => {
|
|
27
|
+
const { schedulerData, resourceEvents } = props;
|
|
28
|
+
const { localeDayjs, config } = schedulerData;
|
|
29
|
+
const event = monitor.getItem();
|
|
30
|
+
const pos = getPos(component.eventContainer);
|
|
31
|
+
const column = Math.floor((monitor.getClientOffset().x - pos.x) / schedulerData.getContentCellWidth());
|
|
32
|
+
const header = resourceEvents.headerItems[Math.max(0, Math.min(column, resourceEvents.headerItems.length - 1))];
|
|
33
|
+
if (!header)
|
|
34
|
+
return null;
|
|
35
|
+
const grabbedSlotId = this.sourceMap.get(monitor.getItemType())?.dragSlotId ?? resourceEvents.slotId;
|
|
36
|
+
const shift = localeDayjs(resourceEvents.slotId).diff(localeDayjs(grabbedSlotId));
|
|
37
|
+
const start = localeDayjs(event.start).add(shift, 'ms');
|
|
38
|
+
const end = start.add(localeDayjs(event.end).diff(localeDayjs(event.start)), 'ms');
|
|
39
|
+
// crossResourceMove disabled: the event stays in its resource and only moves in time
|
|
40
|
+
const keepResource = config.crossResourceMove === false;
|
|
41
|
+
const slotId = keepResource ? schedulerData._getEventSlotId(event) : header.id;
|
|
42
|
+
const slotName = schedulerData.getSlotById(slotId)?.name;
|
|
43
|
+
return {
|
|
44
|
+
slotId,
|
|
45
|
+
slotName,
|
|
46
|
+
start: start.format(DATETIME_FORMAT),
|
|
47
|
+
end: end.format(DATETIME_FORMAT),
|
|
48
|
+
isVertical: true,
|
|
49
|
+
};
|
|
56
50
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
first = covered[0];
|
|
75
|
-
count = covered.length;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
left: first * cellWidth,
|
|
80
|
-
width: count * cellWidth
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
getDropSpec = () => ({
|
|
84
|
-
drop: (props, monitor, component) => {
|
|
85
|
-
const {
|
|
86
|
-
schedulerData,
|
|
87
|
-
resourceEvents
|
|
88
|
-
} = props;
|
|
89
|
-
const {
|
|
90
|
-
cellUnit,
|
|
91
|
-
localeDayjs
|
|
92
|
-
} = schedulerData;
|
|
93
|
-
const type = monitor.getItemType();
|
|
94
|
-
if (schedulerData.isVerticalResourceView() && type === DnDTypes.EVENT) {
|
|
95
|
-
return this.getVerticalMove(props, monitor, component);
|
|
96
|
-
}
|
|
97
|
-
const pos = getPos(component.eventContainer);
|
|
98
|
-
const cellWidth = schedulerData.getContentCellWidth();
|
|
99
|
-
let initialStartTime = null;
|
|
100
|
-
let initialEndTime = null;
|
|
101
|
-
if (type === DnDTypes.EVENT) {
|
|
102
|
-
const {
|
|
103
|
-
initialStart,
|
|
104
|
-
initialEnd
|
|
105
|
-
} = this.extractInitialTimes(monitor, pos, cellWidth, resourceEvents, cellUnit, localeDayjs);
|
|
106
|
-
initialStartTime = initialStart;
|
|
107
|
-
initialEndTime = initialEnd;
|
|
108
|
-
}
|
|
109
|
-
const point = monitor.getClientOffset();
|
|
110
|
-
const leftIndex = Math.floor((point.x - pos.x) / cellWidth);
|
|
111
|
-
const startTime = resourceEvents.headerItems[leftIndex].start;
|
|
112
|
-
let endTime = resourceEvents.headerItems[leftIndex].end;
|
|
113
|
-
if (cellUnit !== CellUnit.Hour) {
|
|
114
|
-
endTime = localeDayjs(new Date(resourceEvents.headerItems[leftIndex].start)).hour(23).minute(59).second(59).format(DATETIME_FORMAT);
|
|
115
|
-
}
|
|
116
|
-
return {
|
|
117
|
-
slotId: resourceEvents.slotId,
|
|
118
|
-
slotName: resourceEvents.slotName,
|
|
119
|
-
start: startTime,
|
|
120
|
-
end: endTime,
|
|
121
|
-
initialStart: initialStartTime,
|
|
122
|
-
initialEnd: initialEndTime
|
|
123
|
-
};
|
|
124
|
-
},
|
|
125
|
-
hover: (props, monitor, component) => {
|
|
126
|
-
const {
|
|
127
|
-
schedulerData,
|
|
128
|
-
resourceEvents,
|
|
129
|
-
movingEvent
|
|
130
|
-
} = props;
|
|
131
|
-
const {
|
|
132
|
-
cellUnit,
|
|
133
|
-
config,
|
|
134
|
-
viewType,
|
|
135
|
-
localeDayjs
|
|
136
|
-
} = schedulerData;
|
|
137
|
-
this.config = config;
|
|
138
|
-
const item = monitor.getItem();
|
|
139
|
-
const type = monitor.getItemType();
|
|
140
|
-
if (schedulerData.isVerticalResourceView() && type === DnDTypes.EVENT) {
|
|
141
|
-
const move = this.getVerticalMove(props, monitor, component);
|
|
142
|
-
const column = Math.floor((monitor.getClientOffset().x - getPos(component.eventContainer).x) / schedulerData.getContentCellWidth());
|
|
143
|
-
const columnIndex = Math.max(0, Math.min(column, resourceEvents.headerItems.length - 1));
|
|
144
|
-
component.setDropPreview?.(this.getDropPreview(resourceEvents, schedulerData.getContentCellWidth(), columnIndex));
|
|
145
|
-
if (move && movingEvent) {
|
|
146
|
-
movingEvent(schedulerData, move.slotId, move.slotName, move.start, move.end, 'Move', type, item);
|
|
147
|
-
}
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
const pos = getPos(component.eventContainer);
|
|
151
|
-
const cellWidth = schedulerData.getContentCellWidth();
|
|
152
|
-
let initialStart = null;
|
|
153
|
-
if (type === DnDTypes.EVENT) {
|
|
154
|
-
const {
|
|
155
|
-
initialStart: iStart
|
|
156
|
-
} = this.extractInitialTimes(monitor, pos, cellWidth, resourceEvents, cellUnit, localeDayjs);
|
|
157
|
-
initialStart = iStart;
|
|
158
|
-
}
|
|
159
|
-
const point = monitor.getClientOffset();
|
|
160
|
-
const leftIndex = Math.floor((point.x - pos.x) / cellWidth);
|
|
161
|
-
if (!resourceEvents.headerItems[leftIndex]) {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
let newStart = resourceEvents.headerItems[leftIndex].start;
|
|
165
|
-
let newEnd = resourceEvents.headerItems[leftIndex].end;
|
|
166
|
-
if (cellUnit !== CellUnit.Hour) {
|
|
167
|
-
newEnd = localeDayjs(new Date(resourceEvents.headerItems[leftIndex].start)).hour(23).minute(59).second(59).format(DATETIME_FORMAT);
|
|
168
|
-
}
|
|
169
|
-
let {
|
|
170
|
-
slotId,
|
|
171
|
-
slotName
|
|
172
|
-
} = resourceEvents;
|
|
173
|
-
let action = 'New';
|
|
174
|
-
const isEvent = type === DnDTypes.EVENT;
|
|
175
|
-
if (isEvent) {
|
|
176
|
-
const event = item;
|
|
177
|
-
if (config.relativeMove) {
|
|
178
|
-
newStart = localeDayjs(event.start).add(localeDayjs(newStart).diff(localeDayjs(new Date(initialStart))), 'ms').format(DATETIME_FORMAT);
|
|
179
|
-
} else if (viewType !== ViewType.Day) {
|
|
180
|
-
const tmpDayjs = localeDayjs(newStart);
|
|
181
|
-
newStart = localeDayjs(event.start).year(tmpDayjs.year()).month(tmpDayjs.month()).date(tmpDayjs.date()).format(DATETIME_FORMAT);
|
|
51
|
+
// Box shown while dragging: the cells (in this row) the dragged item would cover, as { left, width }.
|
|
52
|
+
getDropPreview = (resourceEvents, cellWidth, firstIndex, start, end) => {
|
|
53
|
+
const { headerItems } = resourceEvents;
|
|
54
|
+
let first = firstIndex;
|
|
55
|
+
let count = 1;
|
|
56
|
+
if (start && end) {
|
|
57
|
+
const from = new Date(start);
|
|
58
|
+
const to = new Date(end);
|
|
59
|
+
const covered = headerItems.reduce((acc, header, index) => {
|
|
60
|
+
if (new Date(header.end) > from && new Date(header.start) < to)
|
|
61
|
+
acc.push(index);
|
|
62
|
+
return acc;
|
|
63
|
+
}, []);
|
|
64
|
+
if (covered.length > 0) {
|
|
65
|
+
first = covered[0];
|
|
66
|
+
count = covered.length;
|
|
67
|
+
}
|
|
182
68
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
69
|
+
return { left: first * cellWidth, width: count * cellWidth };
|
|
70
|
+
};
|
|
71
|
+
getDropSpec = () => ({
|
|
72
|
+
drop: (props, monitor, component) => {
|
|
73
|
+
const { schedulerData, resourceEvents } = props;
|
|
74
|
+
const { cellUnit, localeDayjs } = schedulerData;
|
|
75
|
+
const type = monitor.getItemType();
|
|
76
|
+
if (schedulerData.isVerticalResourceView() && type === DnDTypes.EVENT) {
|
|
77
|
+
return this.getVerticalMove(props, monitor, component) ?? undefined;
|
|
78
|
+
}
|
|
79
|
+
const pos = getPos(component.eventContainer);
|
|
80
|
+
const cellWidth = schedulerData.getContentCellWidth();
|
|
81
|
+
let initialStartTime = null;
|
|
82
|
+
let initialEndTime = null;
|
|
83
|
+
if (type === DnDTypes.EVENT) {
|
|
84
|
+
const { initialStart, initialEnd } = this.extractInitialTimes(monitor, pos, cellWidth, resourceEvents, cellUnit, localeDayjs);
|
|
85
|
+
initialStartTime = initialStart;
|
|
86
|
+
initialEndTime = initialEnd;
|
|
87
|
+
}
|
|
88
|
+
const point = monitor.getClientOffset();
|
|
89
|
+
const leftIndex = Math.floor((point.x - pos.x) / cellWidth);
|
|
90
|
+
const startTime = resourceEvents.headerItems[leftIndex].start;
|
|
91
|
+
let endTime = resourceEvents.headerItems[leftIndex].end;
|
|
92
|
+
if (cellUnit !== CellUnit.Hour) {
|
|
93
|
+
endTime = localeDayjs(new Date(resourceEvents.headerItems[leftIndex].start))
|
|
94
|
+
.hour(23)
|
|
95
|
+
.minute(59)
|
|
96
|
+
.second(59)
|
|
97
|
+
.format(DATETIME_FORMAT);
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
slotId: resourceEvents.slotId,
|
|
101
|
+
slotName: resourceEvents.slotName,
|
|
102
|
+
start: startTime,
|
|
103
|
+
end: endTime,
|
|
104
|
+
initialStart: initialStartTime,
|
|
105
|
+
initialEnd: initialEndTime,
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
hover: (props, monitor, component) => {
|
|
109
|
+
const { schedulerData, resourceEvents, movingEvent } = props;
|
|
110
|
+
const { cellUnit, config, viewType, localeDayjs } = schedulerData;
|
|
111
|
+
this.config = config;
|
|
112
|
+
const item = monitor.getItem();
|
|
113
|
+
const type = monitor.getItemType();
|
|
114
|
+
if (schedulerData.isVerticalResourceView() && type === DnDTypes.EVENT) {
|
|
115
|
+
const move = this.getVerticalMove(props, monitor, component);
|
|
116
|
+
const column = Math.floor((monitor.getClientOffset().x - getPos(component.eventContainer).x) /
|
|
117
|
+
schedulerData.getContentCellWidth());
|
|
118
|
+
const columnIndex = Math.max(0, Math.min(column, resourceEvents.headerItems.length - 1));
|
|
119
|
+
component.setDropPreview?.(this.getDropPreview(resourceEvents, schedulerData.getContentCellWidth(), columnIndex));
|
|
120
|
+
if (move && movingEvent) {
|
|
121
|
+
movingEvent(schedulerData, move.slotId, move.slotName, move.start, move.end, 'Move', type, item);
|
|
122
|
+
}
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const pos = getPos(component.eventContainer);
|
|
126
|
+
const cellWidth = schedulerData.getContentCellWidth();
|
|
127
|
+
let initialStart = null;
|
|
128
|
+
if (type === DnDTypes.EVENT) {
|
|
129
|
+
const { initialStart: iStart } = this.extractInitialTimes(monitor, pos, cellWidth, resourceEvents, cellUnit, localeDayjs);
|
|
130
|
+
initialStart = iStart;
|
|
131
|
+
}
|
|
132
|
+
const point = monitor.getClientOffset();
|
|
133
|
+
const leftIndex = Math.floor((point.x - pos.x) / cellWidth);
|
|
134
|
+
if (!resourceEvents.headerItems[leftIndex]) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
let newStart = resourceEvents.headerItems[leftIndex].start;
|
|
138
|
+
let newEnd = resourceEvents.headerItems[leftIndex].end;
|
|
139
|
+
if (cellUnit !== CellUnit.Hour) {
|
|
140
|
+
newEnd = localeDayjs(new Date(resourceEvents.headerItems[leftIndex].start))
|
|
141
|
+
.hour(23)
|
|
142
|
+
.minute(59)
|
|
143
|
+
.second(59)
|
|
144
|
+
.format(DATETIME_FORMAT);
|
|
145
|
+
}
|
|
146
|
+
let { slotId } = resourceEvents;
|
|
147
|
+
let slotName = resourceEvents.slotName;
|
|
148
|
+
let action = 'New';
|
|
149
|
+
const isEvent = type === DnDTypes.EVENT;
|
|
150
|
+
if (isEvent) {
|
|
151
|
+
const event = item; // an EVENT drag always carries an event
|
|
152
|
+
if (config.relativeMove) {
|
|
153
|
+
newStart = localeDayjs(event.start)
|
|
154
|
+
.add(localeDayjs(newStart).diff(localeDayjs(new Date(initialStart))), 'ms')
|
|
155
|
+
.format(DATETIME_FORMAT);
|
|
156
|
+
}
|
|
157
|
+
else if (viewType !== ViewType.Day) {
|
|
158
|
+
const tmpDayjs = localeDayjs(newStart);
|
|
159
|
+
newStart = localeDayjs(event.start)
|
|
160
|
+
.year(tmpDayjs.year())
|
|
161
|
+
.month(tmpDayjs.month())
|
|
162
|
+
.date(tmpDayjs.date())
|
|
163
|
+
.format(DATETIME_FORMAT);
|
|
164
|
+
}
|
|
165
|
+
newEnd = localeDayjs(newStart)
|
|
166
|
+
.add(localeDayjs(event.end).diff(localeDayjs(event.start)), 'ms')
|
|
167
|
+
.format(DATETIME_FORMAT);
|
|
168
|
+
// if crossResourceMove disabled, slot returns old value
|
|
169
|
+
if (config.crossResourceMove === false) {
|
|
170
|
+
slotId = schedulerData._getEventSlotId(event);
|
|
171
|
+
slotName = undefined;
|
|
172
|
+
const slot = schedulerData.getSlotById(slotId);
|
|
173
|
+
if (slot)
|
|
174
|
+
slotName = slot.name;
|
|
175
|
+
}
|
|
176
|
+
action = 'Move';
|
|
177
|
+
}
|
|
178
|
+
component.setDropPreview?.(this.getDropPreview(resourceEvents, cellWidth, leftIndex, isEvent ? newStart : undefined, isEvent ? newEnd : undefined));
|
|
179
|
+
if (movingEvent) {
|
|
180
|
+
movingEvent(schedulerData, slotId, slotName, newStart, newEnd, action, type, item);
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
canDrop: (props, monitor) => {
|
|
184
|
+
const { schedulerData, resourceEvents } = props;
|
|
185
|
+
const item = monitor.getItem();
|
|
186
|
+
if (schedulerData._isResizing())
|
|
187
|
+
return false;
|
|
188
|
+
const { config } = schedulerData;
|
|
189
|
+
return config.movable && !resourceEvents.groupOnly && (item.movable === undefined || item.movable !== false);
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
// Returns the drop specification for use with useDrop hook
|
|
193
|
+
// This should be called with props from the component using the hook
|
|
194
|
+
getDropOptions = (props, component) => {
|
|
195
|
+
const spec = this.getDropSpec();
|
|
196
|
+
return {
|
|
197
|
+
accept: [...this.sourceMap.keys()],
|
|
198
|
+
drop: (_item, monitor) => spec.drop(props, monitor, component),
|
|
199
|
+
hover: (_item, monitor) => spec.hover(props, monitor, component),
|
|
200
|
+
canDrop: (_item, monitor) => spec.canDrop(props, monitor),
|
|
201
|
+
collect: monitor => ({
|
|
202
|
+
isOver: monitor.isOver(),
|
|
203
|
+
canDrop: monitor.canDrop(),
|
|
204
|
+
}),
|
|
205
|
+
};
|
|
226
206
|
};
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
207
|
+
getDndSource = (dndType = DnDTypes.EVENT) => this.sourceMap.get(dndType);
|
|
208
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { DragSourceHookSpec, DragSourceMonitor } from 'react-dnd';
|
|
2
|
+
import type { Id, RenderItem, SchedulerEvent } from '../types';
|
|
3
|
+
import type SchedulerData from './SchedulerData';
|
|
4
|
+
/** What is being dragged: an existing event, or a custom object from an external drag source. */
|
|
5
|
+
export interface DragItem {
|
|
6
|
+
id?: Id;
|
|
7
|
+
title?: string;
|
|
8
|
+
start?: string;
|
|
9
|
+
end?: string;
|
|
10
|
+
resourceId?: Id;
|
|
11
|
+
movable?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** react-dnd item type identifier. */
|
|
14
|
+
export type Identifier = string | symbol;
|
|
15
|
+
export type DnDAction = 'New' | 'Move';
|
|
16
|
+
/** Value returned by the drop target (see DnDContext) and read back in endDrag. */
|
|
17
|
+
export interface DropResult {
|
|
18
|
+
slotId: Id;
|
|
19
|
+
slotName?: string;
|
|
20
|
+
start: string;
|
|
21
|
+
end: string;
|
|
22
|
+
initialStart?: string | null;
|
|
23
|
+
initialEnd?: string | null;
|
|
24
|
+
isVertical?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** Props the component owning the drag source passes to getDragSpec/getDragOptions. */
|
|
27
|
+
export interface DnDSourceProps {
|
|
28
|
+
schedulerData: SchedulerData;
|
|
29
|
+
slotId?: Id;
|
|
30
|
+
resourceEvents?: RenderItem;
|
|
31
|
+
moveEvent?(schedulerData: SchedulerData, event: SchedulerEvent, slotId: Id, slotName: string | undefined, start: string, end: string): void;
|
|
32
|
+
newEvent?(schedulerData: SchedulerData, slotId: Id, slotName: string | undefined, start: string, end: string, type: Identifier, item: DragItem): void;
|
|
33
|
+
conflictOccurred?(schedulerData: SchedulerData, action: DnDAction, item: DragItem, type: Identifier, slotId: Id, slotName: string | undefined, start: string, end: string): void;
|
|
34
|
+
}
|
|
35
|
+
export default class DnDSource {
|
|
36
|
+
resolveDragObjFunc: (props: never) => DragItem;
|
|
37
|
+
dndType: string;
|
|
38
|
+
DnDEnabled: boolean;
|
|
39
|
+
dragSlotId: Id | undefined;
|
|
40
|
+
constructor(resolveDragObjFunc: (props: never) => DragItem, DnDEnabled: boolean, dndType?: string);
|
|
41
|
+
getDragSpec: () => {
|
|
42
|
+
beginDrag: (props: DnDSourceProps) => DragItem;
|
|
43
|
+
endDrag: (props: DnDSourceProps, monitor: DragSourceMonitor<DragItem, DropResult>) => void;
|
|
44
|
+
canDrag: (props: DnDSourceProps) => boolean;
|
|
45
|
+
};
|
|
46
|
+
getDragOptions: (props: DnDSourceProps) => DragSourceHookSpec<DragItem, DropResult, {
|
|
47
|
+
isDragging: boolean;
|
|
48
|
+
}>;
|
|
49
|
+
}
|