resourcenest 1.2.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/CHANGELOG.md +41 -0
- package/LICENSE +21 -0
- package/README.md +324 -0
- package/dist/resourcenest.js +586 -0
- package/dist/resourcenest.umd.cjs +304 -0
- package/package.json +69 -0
- package/src/ResourceNest.js +845 -0
- package/src/index.js +10 -0
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
function M(s) {
|
|
2
|
+
const t = s.getHours().toString().padStart(2, "0"), e = s.getMinutes().toString().padStart(2, "0");
|
|
3
|
+
return `${t}:${e}`;
|
|
4
|
+
}
|
|
5
|
+
function x(s, t = "DD.MM.YYYY") {
|
|
6
|
+
const e = s.getDate().toString().padStart(2, "0"), o = (s.getMonth() + 1).toString().padStart(2, "0"), r = s.getFullYear();
|
|
7
|
+
return t.replace("DD", e).replace("MM", o).replace("YYYY", r);
|
|
8
|
+
}
|
|
9
|
+
function k(s) {
|
|
10
|
+
return new Date(s.getFullYear(), s.getMonth(), s.getDate(), 0, 0, 0, 0);
|
|
11
|
+
}
|
|
12
|
+
function C(s, t) {
|
|
13
|
+
const e = new Date(s);
|
|
14
|
+
return e.setDate(e.getDate() + t), e;
|
|
15
|
+
}
|
|
16
|
+
function y(s, t) {
|
|
17
|
+
return s.getFullYear() === t.getFullYear() && s.getMonth() === t.getMonth() && s.getDate() === t.getDate();
|
|
18
|
+
}
|
|
19
|
+
function T(s, t = 5) {
|
|
20
|
+
const e = 6e4 * t;
|
|
21
|
+
return new Date(Math.round(s.getTime() / e) * e);
|
|
22
|
+
}
|
|
23
|
+
const L = {
|
|
24
|
+
startHour: 8,
|
|
25
|
+
endHour: 22,
|
|
26
|
+
events: [],
|
|
27
|
+
resources: [],
|
|
28
|
+
locale: "de-DE",
|
|
29
|
+
dateFormat: "DD.MM.YYYY",
|
|
30
|
+
todayLabel: "Today",
|
|
31
|
+
loadingLabel: "Loading...",
|
|
32
|
+
showNavigation: !0,
|
|
33
|
+
showNowIndicator: !0,
|
|
34
|
+
showViewSwitcher: !0,
|
|
35
|
+
eventClickable: !0,
|
|
36
|
+
timeClickable: !0,
|
|
37
|
+
// View modes: 'day', '3days', 'week'
|
|
38
|
+
view: "day",
|
|
39
|
+
viewLabels: {
|
|
40
|
+
day: "Day",
|
|
41
|
+
"3days": "3 Days",
|
|
42
|
+
week: "Week"
|
|
43
|
+
},
|
|
44
|
+
// Callbacks
|
|
45
|
+
onEventClick: null,
|
|
46
|
+
onTimeClick: null,
|
|
47
|
+
onDateChange: null,
|
|
48
|
+
onViewChange: null
|
|
49
|
+
}, I = `
|
|
50
|
+
.rn-timeline-calendar {
|
|
51
|
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
52
|
+
background: #fff;
|
|
53
|
+
border-radius: 8px;
|
|
54
|
+
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
|
|
55
|
+
padding: 1rem;
|
|
56
|
+
box-sizing: border-box;
|
|
57
|
+
}
|
|
58
|
+
.rn-timeline-calendar *, .rn-timeline-calendar *::before, .rn-timeline-calendar *::after {
|
|
59
|
+
box-sizing: border-box;
|
|
60
|
+
}
|
|
61
|
+
.rn-calendar-header {
|
|
62
|
+
display: flex;
|
|
63
|
+
justify-content: space-between;
|
|
64
|
+
align-items: center;
|
|
65
|
+
margin-bottom: 1rem;
|
|
66
|
+
flex-wrap: wrap;
|
|
67
|
+
gap: 0.5rem;
|
|
68
|
+
}
|
|
69
|
+
.rn-date-display {
|
|
70
|
+
font-size: 1.25rem;
|
|
71
|
+
font-weight: 700;
|
|
72
|
+
color: #111827;
|
|
73
|
+
}
|
|
74
|
+
.rn-nav-controls {
|
|
75
|
+
display: flex;
|
|
76
|
+
gap: 0.5rem;
|
|
77
|
+
align-items: center;
|
|
78
|
+
}
|
|
79
|
+
.rn-btn {
|
|
80
|
+
display: inline-flex;
|
|
81
|
+
align-items: center;
|
|
82
|
+
justify-content: center;
|
|
83
|
+
padding: 8px 16px;
|
|
84
|
+
border-radius: 6px;
|
|
85
|
+
font-size: 0.875rem;
|
|
86
|
+
font-weight: 500;
|
|
87
|
+
cursor: pointer;
|
|
88
|
+
border: 1px solid #d1d5db;
|
|
89
|
+
background: #fff;
|
|
90
|
+
color: #374151;
|
|
91
|
+
transition: background 0.15s, border-color 0.15s;
|
|
92
|
+
}
|
|
93
|
+
.rn-btn:hover {
|
|
94
|
+
background: #f9fafb;
|
|
95
|
+
border-color: #9ca3af;
|
|
96
|
+
}
|
|
97
|
+
.rn-btn:disabled {
|
|
98
|
+
opacity: 0.5;
|
|
99
|
+
cursor: not-allowed;
|
|
100
|
+
}
|
|
101
|
+
.rn-btn-icon {
|
|
102
|
+
padding: 8px;
|
|
103
|
+
min-width: 36px;
|
|
104
|
+
}
|
|
105
|
+
.rn-calendar-body {
|
|
106
|
+
display: flex;
|
|
107
|
+
position: relative;
|
|
108
|
+
border: 1px solid #e5e7eb;
|
|
109
|
+
border-radius: 4px;
|
|
110
|
+
min-height: 200px;
|
|
111
|
+
overflow: hidden;
|
|
112
|
+
}
|
|
113
|
+
.rn-loading-overlay {
|
|
114
|
+
position: absolute;
|
|
115
|
+
inset: 0;
|
|
116
|
+
background: rgba(255,255,255,0.8);
|
|
117
|
+
display: flex;
|
|
118
|
+
align-items: center;
|
|
119
|
+
justify-content: center;
|
|
120
|
+
z-index: 100;
|
|
121
|
+
font-weight: 600;
|
|
122
|
+
color: #6b7280;
|
|
123
|
+
}
|
|
124
|
+
.rn-resource-sidebar {
|
|
125
|
+
width: 140px;
|
|
126
|
+
flex-shrink: 0;
|
|
127
|
+
background: #f9fafb;
|
|
128
|
+
border-right: 1px solid #e5e7eb;
|
|
129
|
+
margin-top: 40px;
|
|
130
|
+
}
|
|
131
|
+
.rn-resource-row {
|
|
132
|
+
display: flex;
|
|
133
|
+
align-items: center;
|
|
134
|
+
height: 60px;
|
|
135
|
+
padding: 0 1rem;
|
|
136
|
+
border-bottom: 1px solid #e5e7eb;
|
|
137
|
+
font-size: 0.875rem;
|
|
138
|
+
font-weight: 500;
|
|
139
|
+
white-space: nowrap;
|
|
140
|
+
overflow: hidden;
|
|
141
|
+
text-overflow: ellipsis;
|
|
142
|
+
}
|
|
143
|
+
.rn-chart {
|
|
144
|
+
flex: 1;
|
|
145
|
+
overflow-x: auto;
|
|
146
|
+
}
|
|
147
|
+
.rn-hour-labels {
|
|
148
|
+
display: flex;
|
|
149
|
+
height: 40px;
|
|
150
|
+
background: #f3f4f6;
|
|
151
|
+
border-bottom: 1px solid #e5e7eb;
|
|
152
|
+
}
|
|
153
|
+
.rn-hour-cell {
|
|
154
|
+
flex: 1;
|
|
155
|
+
min-width: 80px;
|
|
156
|
+
display: flex;
|
|
157
|
+
align-items: center;
|
|
158
|
+
justify-content: center;
|
|
159
|
+
font-size: 0.75rem;
|
|
160
|
+
color: #4b5563;
|
|
161
|
+
border-right: 1px solid #e5e7eb;
|
|
162
|
+
}
|
|
163
|
+
.rn-hour-cell.is-current {
|
|
164
|
+
background: #dbeafe;
|
|
165
|
+
font-weight: 600;
|
|
166
|
+
color: #1d4ed8;
|
|
167
|
+
}
|
|
168
|
+
.rn-timeline {
|
|
169
|
+
position: relative;
|
|
170
|
+
}
|
|
171
|
+
.rn-timeline-row {
|
|
172
|
+
display: flex;
|
|
173
|
+
height: 60px;
|
|
174
|
+
position: relative;
|
|
175
|
+
}
|
|
176
|
+
.rn-timeline-cell {
|
|
177
|
+
flex: 1;
|
|
178
|
+
min-width: 80px;
|
|
179
|
+
border-right: 1px solid #e5e7eb;
|
|
180
|
+
border-bottom: 1px solid #e5e7eb;
|
|
181
|
+
}
|
|
182
|
+
.rn-timeline-cell.is-current {
|
|
183
|
+
background: #eff6ff;
|
|
184
|
+
}
|
|
185
|
+
.rn-event {
|
|
186
|
+
position: absolute;
|
|
187
|
+
top: 6px;
|
|
188
|
+
height: calc(100% - 12px);
|
|
189
|
+
background: #3b82f6;
|
|
190
|
+
color: #fff;
|
|
191
|
+
padding: 4px 8px;
|
|
192
|
+
border-radius: 4px;
|
|
193
|
+
font-size: 0.75rem;
|
|
194
|
+
overflow: hidden;
|
|
195
|
+
cursor: pointer;
|
|
196
|
+
z-index: 10;
|
|
197
|
+
box-shadow: 0 1px 2px rgb(0 0 0 / 0.1);
|
|
198
|
+
transition: transform 0.1s;
|
|
199
|
+
}
|
|
200
|
+
.rn-event:hover {
|
|
201
|
+
transform: scale(1.02);
|
|
202
|
+
z-index: 20;
|
|
203
|
+
}
|
|
204
|
+
.rn-event.status-cancelled {
|
|
205
|
+
background: #ef4444;
|
|
206
|
+
}
|
|
207
|
+
.rn-event.status-confirmed {
|
|
208
|
+
background: #10b981;
|
|
209
|
+
}
|
|
210
|
+
.rn-event-time {
|
|
211
|
+
font-weight: 700;
|
|
212
|
+
}
|
|
213
|
+
.rn-event-label {
|
|
214
|
+
white-space: nowrap;
|
|
215
|
+
overflow: hidden;
|
|
216
|
+
text-overflow: ellipsis;
|
|
217
|
+
}
|
|
218
|
+
.rn-event-guests {
|
|
219
|
+
font-size: 0.7rem;
|
|
220
|
+
opacity: 0.9;
|
|
221
|
+
}
|
|
222
|
+
.rn-now-indicator {
|
|
223
|
+
position: absolute;
|
|
224
|
+
top: 0;
|
|
225
|
+
bottom: 0;
|
|
226
|
+
width: 2px;
|
|
227
|
+
background: #ef4444;
|
|
228
|
+
z-index: 30;
|
|
229
|
+
pointer-events: none;
|
|
230
|
+
}
|
|
231
|
+
.rn-now-indicator::before {
|
|
232
|
+
content: '';
|
|
233
|
+
position: absolute;
|
|
234
|
+
top: 0;
|
|
235
|
+
left: -4px;
|
|
236
|
+
width: 10px;
|
|
237
|
+
height: 10px;
|
|
238
|
+
background: #ef4444;
|
|
239
|
+
border-radius: 50%;
|
|
240
|
+
}
|
|
241
|
+
.rn-view-switcher {
|
|
242
|
+
display: flex;
|
|
243
|
+
gap: 0;
|
|
244
|
+
border: 1px solid #d1d5db;
|
|
245
|
+
border-radius: 6px;
|
|
246
|
+
overflow: hidden;
|
|
247
|
+
}
|
|
248
|
+
.rn-view-btn {
|
|
249
|
+
padding: 6px 12px;
|
|
250
|
+
font-size: 0.8rem;
|
|
251
|
+
font-weight: 500;
|
|
252
|
+
cursor: pointer;
|
|
253
|
+
border: none;
|
|
254
|
+
background: #fff;
|
|
255
|
+
color: #374151;
|
|
256
|
+
transition: background 0.15s;
|
|
257
|
+
border-right: 1px solid #d1d5db;
|
|
258
|
+
}
|
|
259
|
+
.rn-view-btn:last-child {
|
|
260
|
+
border-right: none;
|
|
261
|
+
}
|
|
262
|
+
.rn-view-btn:hover {
|
|
263
|
+
background: #f3f4f6;
|
|
264
|
+
}
|
|
265
|
+
.rn-view-btn.is-active {
|
|
266
|
+
background: #3b82f6;
|
|
267
|
+
color: #fff;
|
|
268
|
+
}
|
|
269
|
+
.rn-day-header {
|
|
270
|
+
display: flex;
|
|
271
|
+
background: #f3f4f6;
|
|
272
|
+
border-bottom: 1px solid #e5e7eb;
|
|
273
|
+
}
|
|
274
|
+
.rn-day-column-header {
|
|
275
|
+
flex: 1;
|
|
276
|
+
text-align: center;
|
|
277
|
+
padding: 8px 4px;
|
|
278
|
+
font-size: 0.75rem;
|
|
279
|
+
font-weight: 600;
|
|
280
|
+
color: #374151;
|
|
281
|
+
border-right: 1px solid #e5e7eb;
|
|
282
|
+
}
|
|
283
|
+
.rn-day-column-header:last-child {
|
|
284
|
+
border-right: none;
|
|
285
|
+
}
|
|
286
|
+
.rn-day-column-header.is-today {
|
|
287
|
+
background: #dbeafe;
|
|
288
|
+
color: #1d4ed8;
|
|
289
|
+
}
|
|
290
|
+
.rn-multi-day-timeline {
|
|
291
|
+
display: flex;
|
|
292
|
+
}
|
|
293
|
+
.rn-day-column {
|
|
294
|
+
flex: 1;
|
|
295
|
+
border-right: 1px solid #e5e7eb;
|
|
296
|
+
}
|
|
297
|
+
.rn-day-column:last-child {
|
|
298
|
+
border-right: none;
|
|
299
|
+
}
|
|
300
|
+
`;
|
|
301
|
+
function V() {
|
|
302
|
+
if (document.getElementById("rn-timeline-calendar-styles")) return;
|
|
303
|
+
const s = document.createElement("style");
|
|
304
|
+
s.id = "rn-timeline-calendar-styles", s.textContent = I, document.head.appendChild(s);
|
|
305
|
+
}
|
|
306
|
+
class Y {
|
|
307
|
+
constructor(t, e = {}) {
|
|
308
|
+
if (this.root = typeof t == "string" ? document.querySelector(t) : t, !this.root)
|
|
309
|
+
throw new Error(`ResourceNest: Element "${t}" not found`);
|
|
310
|
+
this.options = { ...L, ...e }, this.currentDate = k(/* @__PURE__ */ new Date()), this.events = this._normalizeEvents(this.options.events), this.resources = this.options.resources || [], this.loading = !1, this.view = this.options.view || "day", V(), this._render();
|
|
311
|
+
}
|
|
312
|
+
// ============ PUBLIC API ============
|
|
313
|
+
/** Set events and re-render */
|
|
314
|
+
setEvents(t) {
|
|
315
|
+
return this.events = this._normalizeEvents(t), this._renderTimeline(), this;
|
|
316
|
+
}
|
|
317
|
+
/** Set resources and re-render */
|
|
318
|
+
setResources(t) {
|
|
319
|
+
return this.resources = t || [], this._render(), this;
|
|
320
|
+
}
|
|
321
|
+
/** Navigate to a specific date */
|
|
322
|
+
setDate(t) {
|
|
323
|
+
return this.currentDate = k(new Date(t)), this._render(), this._emitDateChange(), this;
|
|
324
|
+
}
|
|
325
|
+
/** Navigate to today */
|
|
326
|
+
goToToday() {
|
|
327
|
+
return this.currentDate = k(/* @__PURE__ */ new Date()), this._render(), this._emitDateChange(), this;
|
|
328
|
+
}
|
|
329
|
+
/** Navigate to next day */
|
|
330
|
+
nextDay() {
|
|
331
|
+
const t = this._getViewDays();
|
|
332
|
+
return this.currentDate = C(this.currentDate, t), this._render(), this._emitDateChange(), this;
|
|
333
|
+
}
|
|
334
|
+
/** Navigate to previous day */
|
|
335
|
+
prevDay() {
|
|
336
|
+
const t = this._getViewDays();
|
|
337
|
+
return this.currentDate = C(this.currentDate, -t), this._render(), this._emitDateChange(), this;
|
|
338
|
+
}
|
|
339
|
+
/** Set view mode: 'day', '3days', 'week' */
|
|
340
|
+
setView(t) {
|
|
341
|
+
return ["day", "3days", "week"].includes(t) && (this.view = t, this._render(), this._emitViewChange()), this;
|
|
342
|
+
}
|
|
343
|
+
/** Get current view mode */
|
|
344
|
+
getView() {
|
|
345
|
+
return this.view;
|
|
346
|
+
}
|
|
347
|
+
/** Show loading overlay */
|
|
348
|
+
setLoading(t) {
|
|
349
|
+
this.loading = t;
|
|
350
|
+
const e = this.root.querySelector(".rn-loading-overlay");
|
|
351
|
+
return e && (e.style.display = t ? "flex" : "none"), this;
|
|
352
|
+
}
|
|
353
|
+
/** Refresh the calendar */
|
|
354
|
+
refresh() {
|
|
355
|
+
return this._render(), this;
|
|
356
|
+
}
|
|
357
|
+
/** Scroll to current hour (if today is visible) */
|
|
358
|
+
scrollToNow() {
|
|
359
|
+
const t = this.root.querySelector(".rn-chart"), e = /* @__PURE__ */ new Date();
|
|
360
|
+
if (!t) return this;
|
|
361
|
+
const o = this._getVisibleDates(), r = o.findIndex((n) => y(n, e));
|
|
362
|
+
if (r === -1) return this;
|
|
363
|
+
const { startHour: i, endHour: c } = this.options, l = c - i, a = l * o.length, d = e.getHours() - i, g = (r * l + d) / a;
|
|
364
|
+
return t.scrollLeft = t.scrollWidth * Math.max(0, Math.min(1, g)) - t.clientWidth / 2, this;
|
|
365
|
+
}
|
|
366
|
+
/** Get current date */
|
|
367
|
+
getDate() {
|
|
368
|
+
return new Date(this.currentDate);
|
|
369
|
+
}
|
|
370
|
+
/** Destroy the calendar */
|
|
371
|
+
destroy() {
|
|
372
|
+
this.root.innerHTML = "", this.root.classList.remove("rn-timeline-calendar");
|
|
373
|
+
}
|
|
374
|
+
/** Set callback for event click */
|
|
375
|
+
onEventClick(t) {
|
|
376
|
+
return this.options.onEventClick = t, this;
|
|
377
|
+
}
|
|
378
|
+
/** Set callback for time slot click */
|
|
379
|
+
onTimeClick(t) {
|
|
380
|
+
return this.options.onTimeClick = t, this;
|
|
381
|
+
}
|
|
382
|
+
/** Set callback for date change */
|
|
383
|
+
onDateChange(t) {
|
|
384
|
+
return this.options.onDateChange = t, this;
|
|
385
|
+
}
|
|
386
|
+
/** Set callback for view change */
|
|
387
|
+
onViewChange(t) {
|
|
388
|
+
return this.options.onViewChange = t, this;
|
|
389
|
+
}
|
|
390
|
+
// ============ INTERNAL ============
|
|
391
|
+
_getViewDays() {
|
|
392
|
+
switch (this.view) {
|
|
393
|
+
case "3days":
|
|
394
|
+
return 3;
|
|
395
|
+
case "week":
|
|
396
|
+
return 7;
|
|
397
|
+
default:
|
|
398
|
+
return 1;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
_getVisibleDates() {
|
|
402
|
+
const t = this._getViewDays(), e = [];
|
|
403
|
+
for (let o = 0; o < t; o++)
|
|
404
|
+
e.push(C(this.currentDate, o));
|
|
405
|
+
return e;
|
|
406
|
+
}
|
|
407
|
+
_normalizeEvents(t) {
|
|
408
|
+
return (t || []).map((e) => ({
|
|
409
|
+
id: e.id,
|
|
410
|
+
resourceId: e.resourceId || e.serviceResourceId,
|
|
411
|
+
from: new Date(e.from),
|
|
412
|
+
to: new Date(e.to),
|
|
413
|
+
label: e.label || e.title || e.code || "",
|
|
414
|
+
guestCount: e.guestCount || e.guests || 0,
|
|
415
|
+
status: e.status || null,
|
|
416
|
+
data: e
|
|
417
|
+
// Original data
|
|
418
|
+
}));
|
|
419
|
+
}
|
|
420
|
+
_getHours() {
|
|
421
|
+
const { startHour: t, endHour: e } = this.options, o = [], r = /* @__PURE__ */ new Date();
|
|
422
|
+
for (let i = t; i < e; i++)
|
|
423
|
+
o.push({
|
|
424
|
+
hour: i,
|
|
425
|
+
label: `${i.toString().padStart(2, "0")}:00`,
|
|
426
|
+
isCurrent: y(r, this.currentDate) && r.getHours() === i
|
|
427
|
+
});
|
|
428
|
+
return o;
|
|
429
|
+
}
|
|
430
|
+
_getDayRange() {
|
|
431
|
+
const { startHour: t, endHour: e } = this.options, o = this._getViewDays(), r = new Date(this.currentDate);
|
|
432
|
+
r.setHours(t, 0, 0, 0);
|
|
433
|
+
const i = new Date(this.currentDate);
|
|
434
|
+
return i.setDate(i.getDate() + o - 1), i.setHours(e, 0, 0, 0), { from: r, to: i, rangeMs: i - r };
|
|
435
|
+
}
|
|
436
|
+
_getEventsForResource(t) {
|
|
437
|
+
const { from: e, to: o } = this._getDayRange();
|
|
438
|
+
return this.events.filter((r) => r.resourceId !== t ? !1 : !(r.to <= e || r.from >= o));
|
|
439
|
+
}
|
|
440
|
+
_render() {
|
|
441
|
+
const { showNavigation: t, showViewSwitcher: e, todayLabel: o, loadingLabel: r, dateFormat: i, viewLabels: c } = this.options, l = this._getHours(), a = this._getVisibleDates(), d = a.length > 1;
|
|
442
|
+
let f;
|
|
443
|
+
if (d) {
|
|
444
|
+
const n = a[0], h = a[a.length - 1];
|
|
445
|
+
f = `${x(n, i)} - ${x(h, i)}`;
|
|
446
|
+
} else
|
|
447
|
+
f = x(this.currentDate, i);
|
|
448
|
+
const g = a.flatMap(
|
|
449
|
+
(n, h) => l.map((b) => ({
|
|
450
|
+
...b,
|
|
451
|
+
dayIndex: h,
|
|
452
|
+
date: n,
|
|
453
|
+
isCurrent: y(n, /* @__PURE__ */ new Date()) && (/* @__PURE__ */ new Date()).getHours() === b.hour
|
|
454
|
+
}))
|
|
455
|
+
);
|
|
456
|
+
this.root.classList.add("rn-timeline-calendar"), this.root.innerHTML = `
|
|
457
|
+
<div class="rn-calendar-header">
|
|
458
|
+
<div class="rn-date-display">${f}</div>
|
|
459
|
+
<div class="rn-nav-controls">
|
|
460
|
+
${e ? `
|
|
461
|
+
<div class="rn-view-switcher">
|
|
462
|
+
<button class="rn-view-btn ${this.view === "day" ? "is-active" : ""}" data-view="day">${c.day}</button>
|
|
463
|
+
<button class="rn-view-btn ${this.view === "3days" ? "is-active" : ""}" data-view="3days">${c["3days"]}</button>
|
|
464
|
+
<button class="rn-view-btn ${this.view === "week" ? "is-active" : ""}" data-view="week">${c.week}</button>
|
|
465
|
+
</div>
|
|
466
|
+
` : ""}
|
|
467
|
+
${t ? `
|
|
468
|
+
<button class="rn-btn" data-action="today">${o}</button>
|
|
469
|
+
<button class="rn-btn rn-btn-icon" data-action="prev">‹</button>
|
|
470
|
+
<button class="rn-btn rn-btn-icon" data-action="next">›</button>
|
|
471
|
+
` : ""}
|
|
472
|
+
</div>
|
|
473
|
+
</div>
|
|
474
|
+
<div class="rn-calendar-body">
|
|
475
|
+
<div class="rn-loading-overlay" style="display:${this.loading ? "flex" : "none"}">${r}</div>
|
|
476
|
+
<div class="rn-resource-sidebar">
|
|
477
|
+
${d ? '<div class="rn-resource-row" style="height:40px;"></div>' : ""}
|
|
478
|
+
${this.resources.map((n) => `
|
|
479
|
+
<div class="rn-resource-row" data-resource-id="${n.id || n.Id}">${n.name || n.Name || n.title || "—"}</div>
|
|
480
|
+
`).join("")}
|
|
481
|
+
</div>
|
|
482
|
+
<div class="rn-chart">
|
|
483
|
+
${d ? this._renderMultiDayHeader(a, l.length) : ""}
|
|
484
|
+
<div class="rn-hour-labels">
|
|
485
|
+
${g.map((n) => `
|
|
486
|
+
<div class="rn-hour-cell ${n.isCurrent ? "is-current" : ""}">${n.label}</div>
|
|
487
|
+
`).join("")}
|
|
488
|
+
</div>
|
|
489
|
+
<div class="rn-timeline" data-days="${a.length}" data-hours="${l.length}">
|
|
490
|
+
${this.resources.map((n) => `
|
|
491
|
+
<div class="rn-timeline-row" data-resource-id="${n.id || n.Id}">
|
|
492
|
+
${g.map((h) => `
|
|
493
|
+
<div class="rn-timeline-cell ${h.isCurrent ? "is-current" : ""}" data-day="${h.dayIndex}"></div>
|
|
494
|
+
`).join("")}
|
|
495
|
+
</div>
|
|
496
|
+
`).join("")}
|
|
497
|
+
</div>
|
|
498
|
+
</div>
|
|
499
|
+
</div>
|
|
500
|
+
`, this._bindEvents(), this._renderTimeline(), this.scrollToNow();
|
|
501
|
+
}
|
|
502
|
+
_renderMultiDayHeader(t, e) {
|
|
503
|
+
const o = /* @__PURE__ */ new Date(), r = ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"];
|
|
504
|
+
return `
|
|
505
|
+
<div class="rn-day-header">
|
|
506
|
+
${t.map((i) => {
|
|
507
|
+
const c = y(i, o), l = r[i.getDay()], a = i.getDate();
|
|
508
|
+
return `<div class="rn-day-column-header ${c ? "is-today" : ""}" style="flex: ${e};">${l} ${a}</div>`;
|
|
509
|
+
}).join("")}
|
|
510
|
+
</div>
|
|
511
|
+
`;
|
|
512
|
+
}
|
|
513
|
+
_renderTimeline() {
|
|
514
|
+
const t = this.root.querySelector(".rn-timeline");
|
|
515
|
+
if (!t) return;
|
|
516
|
+
t.querySelectorAll(".rn-event, .rn-now-indicator").forEach((a) => a.remove());
|
|
517
|
+
const e = this._getVisibleDates(), { startHour: o, endHour: r } = this.options, i = r - o, c = i * e.length, l = t.scrollWidth;
|
|
518
|
+
if (this.resources.forEach((a) => {
|
|
519
|
+
const d = a.id || a.Id, f = t.querySelector(`.rn-timeline-row[data-resource-id="${d}"]`);
|
|
520
|
+
if (!f) return;
|
|
521
|
+
this._getEventsForResource(d).forEach((n) => {
|
|
522
|
+
e.forEach((h, b) => {
|
|
523
|
+
const m = new Date(h);
|
|
524
|
+
m.setHours(o, 0, 0, 0);
|
|
525
|
+
const u = new Date(h);
|
|
526
|
+
if (u.setHours(r, 0, 0, 0), n.to <= m || n.from >= u) return;
|
|
527
|
+
const w = n.from < m ? m : n.from, D = n.to > u ? u : n.to, v = w.getHours() - o + w.getMinutes() / 60, H = b * i + v, $ = (D - w) / (1e3 * 60 * 60), _ = l / c * H, S = Math.max(40, l / c * $), p = document.createElement("div");
|
|
528
|
+
p.className = "rn-event", (n.status === "Cancelled" || n.status === "cancelled") && p.classList.add("status-cancelled"), (n.status === "Confirmed" || n.status === "confirmed") && p.classList.add("status-confirmed"), p.style.left = `${_}px`, p.style.width = `${S}px`, p.title = n.label, p.dataset.eventId = n.id, p.innerHTML = `
|
|
529
|
+
<div class="rn-event-time">${M(n.from)}</div>
|
|
530
|
+
<div class="rn-event-label">${n.label}</div>
|
|
531
|
+
${n.guestCount ? `<div class="rn-event-guests">${n.guestCount} people</div>` : ""}
|
|
532
|
+
`, this.options.eventClickable && p.addEventListener("click", (E) => {
|
|
533
|
+
E.stopPropagation(), typeof this.options.onEventClick == "function" && this.options.onEventClick(n.data, n);
|
|
534
|
+
}), f.appendChild(p);
|
|
535
|
+
});
|
|
536
|
+
});
|
|
537
|
+
}), this.options.showNowIndicator) {
|
|
538
|
+
const a = /* @__PURE__ */ new Date(), d = this._getVisibleDates(), f = d.findIndex((g) => y(g, a));
|
|
539
|
+
if (f !== -1 && a.getHours() >= this.options.startHour && a.getHours() < this.options.endHour) {
|
|
540
|
+
const g = this.options.endHour - this.options.startHour, n = g * d.length, h = a.getHours() - this.options.startHour + a.getMinutes() / 60, b = f * g + h, m = l / n * b, u = document.createElement("div");
|
|
541
|
+
u.className = "rn-now-indicator", u.style.left = `${m}px`, t.appendChild(u);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
_bindEvents() {
|
|
546
|
+
const t = this.root.querySelector('[data-action="today"]'), e = this.root.querySelector('[data-action="prev"]'), o = this.root.querySelector('[data-action="next"]');
|
|
547
|
+
if (t && t.addEventListener("click", () => this.goToToday()), e && e.addEventListener("click", () => this.prevDay()), o && o.addEventListener("click", () => this.nextDay()), this.root.querySelectorAll("[data-view]").forEach((r) => {
|
|
548
|
+
r.addEventListener("click", () => {
|
|
549
|
+
const i = r.dataset.view;
|
|
550
|
+
this.setView(i);
|
|
551
|
+
});
|
|
552
|
+
}), this.options.timeClickable) {
|
|
553
|
+
const r = this.root.querySelector(".rn-timeline");
|
|
554
|
+
r && r.addEventListener("click", (i) => this._handleTimelineClick(i));
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
_handleTimelineClick(t) {
|
|
558
|
+
if (t.target.closest(".rn-event")) return;
|
|
559
|
+
const e = t.currentTarget, o = e.getBoundingClientRect(), r = t.clientX - o.left + e.scrollLeft, i = t.clientY - o.top, c = this._getVisibleDates(), { startHour: l, endHour: a } = this.options, d = a - l, f = d * c.length, g = e.scrollWidth, n = r / g * f, h = Math.floor(n / d), b = n % d, m = c[h] || c[0];
|
|
560
|
+
let u = new Date(m);
|
|
561
|
+
u.setHours(l + Math.floor(b), b % 1 * 60, 0, 0), u = T(u, 5);
|
|
562
|
+
const D = Math.floor(i / 60), v = this.resources[D];
|
|
563
|
+
v && typeof this.options.onTimeClick == "function" && this.options.onTimeClick({
|
|
564
|
+
time: u.toISOString(),
|
|
565
|
+
date: u,
|
|
566
|
+
resource: v
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
_emitDateChange() {
|
|
570
|
+
if (typeof this.options.onDateChange == "function") {
|
|
571
|
+
const t = this.currentDate.getFullYear(), e = String(this.currentDate.getMonth() + 1).padStart(2, "0"), o = String(this.currentDate.getDate()).padStart(2, "0"), r = `${t}-${e}-${o}`;
|
|
572
|
+
this.options.onDateChange(r, this.currentDate);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
_emitViewChange() {
|
|
576
|
+
typeof this.options.onViewChange == "function" && this.options.onViewChange(this.view);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
function z(s, t = {}) {
|
|
580
|
+
return new Y(s, t);
|
|
581
|
+
}
|
|
582
|
+
export {
|
|
583
|
+
Y as ResourceNest,
|
|
584
|
+
z as createResourceNest,
|
|
585
|
+
z as default
|
|
586
|
+
};
|