@ziix/calendar 0.1.1 → 0.1.3
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/dist/index.d.ts +26 -0
- package/dist/ziix-calendar.css +1 -1
- package/dist/ziix-calendar.js +419 -335
- package/dist/ziix-calendar.js.map +1 -1
- package/package.json +1 -1
package/dist/ziix-calendar.js
CHANGED
|
@@ -1,44 +1,65 @@
|
|
|
1
1
|
import C from "dayjs";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
C.extend(
|
|
5
|
-
C.extend(
|
|
6
|
-
function b(
|
|
7
|
-
const e = C(
|
|
2
|
+
import _ from "dayjs/plugin/utc";
|
|
3
|
+
import X from "dayjs/plugin/timezone";
|
|
4
|
+
C.extend(_);
|
|
5
|
+
C.extend(X);
|
|
6
|
+
function b(u, t) {
|
|
7
|
+
const e = C(u);
|
|
8
8
|
return t ? e.tz(t) : e;
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
return
|
|
10
|
+
function Y(u) {
|
|
11
|
+
return u ? C().tz(u) : C();
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
const t =
|
|
15
|
-
return e * 60 +
|
|
13
|
+
function L(u) {
|
|
14
|
+
const t = u.split(":"), e = Number(t[0]) || 0, s = Number(t[1]) || 0;
|
|
15
|
+
return e * 60 + s;
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
const t = Math.floor(
|
|
17
|
+
function I(u) {
|
|
18
|
+
const t = Math.floor(u / 60), e = u % 60;
|
|
19
19
|
return `${String(t).padStart(2, "0")}:${String(e).padStart(2, "0")}`;
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
return
|
|
21
|
+
function g(u) {
|
|
22
|
+
return u.hour() * 60 + u.minute();
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
return new Intl.DateTimeFormat(e, { ...t, timeZone:
|
|
24
|
+
function A(u, t, e, s) {
|
|
25
|
+
return new Intl.DateTimeFormat(e, { ...t, timeZone: s }).format(u.toDate());
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
const
|
|
29
|
-
|
|
27
|
+
function P(u, t) {
|
|
28
|
+
const e = [];
|
|
29
|
+
for (const s of t) {
|
|
30
|
+
if (!(s.daysOfWeek ?? [0, 1, 2, 3, 4, 5, 6]).includes(u)) continue;
|
|
31
|
+
const n = L(s.startTime ?? "00:00"), o = L(s.endTime ?? "24:00");
|
|
32
|
+
o > n && e.push([n, o]);
|
|
33
|
+
}
|
|
34
|
+
return e;
|
|
30
35
|
}
|
|
31
|
-
|
|
36
|
+
function R(u, t, e) {
|
|
37
|
+
const s = u.map((r) => [Math.max(r[0], t), Math.min(r[1], e)]).filter((r) => r[1] > r[0]).sort((r, c) => r[0] - c[0]), i = [];
|
|
38
|
+
for (const r of s) {
|
|
39
|
+
const c = i[i.length - 1];
|
|
40
|
+
c && r[0] <= c[1] ? c[1] = Math.max(c[1], r[1]) : i.push([r[0], r[1]]);
|
|
41
|
+
}
|
|
42
|
+
const n = [];
|
|
43
|
+
let o = t;
|
|
44
|
+
for (const r of i)
|
|
45
|
+
r[0] > o && n.push([o, r[0]]), o = r[1];
|
|
46
|
+
return o < e && n.push([o, e]), n;
|
|
47
|
+
}
|
|
48
|
+
function F(u = {}) {
|
|
49
|
+
const t = L(u.min ?? "00:00"), e = L(u.max ?? "24:00"), s = u.duration ?? 15, i = u.labelInterval ?? 60, n = Math.max(0, e - t), o = s > 0 ? Math.ceil(n / s) : 0;
|
|
50
|
+
return { min: t, max: e, duration: s, labelInterval: i, slots: o, totalMinutes: n };
|
|
51
|
+
}
|
|
52
|
+
class V {
|
|
32
53
|
constructor(t) {
|
|
33
54
|
this.tz = t, this.map = /* @__PURE__ */ new Map();
|
|
34
55
|
}
|
|
35
56
|
normalize(t) {
|
|
36
|
-
const e = b(t.start, this.tz),
|
|
57
|
+
const e = b(t.start, this.tz), s = t.end ? b(t.end, this.tz) : e.add(30, "minute");
|
|
37
58
|
return {
|
|
38
59
|
id: String(t.id),
|
|
39
60
|
title: t.title ?? "",
|
|
40
61
|
start: e,
|
|
41
|
-
end:
|
|
62
|
+
end: s,
|
|
42
63
|
resourceId: t.resourceId != null ? String(t.resourceId) : null,
|
|
43
64
|
allDay: !!t.allDay,
|
|
44
65
|
color: t.color,
|
|
@@ -51,8 +72,8 @@ class _ {
|
|
|
51
72
|
set(t) {
|
|
52
73
|
this.map.clear();
|
|
53
74
|
for (const e of t) {
|
|
54
|
-
const
|
|
55
|
-
this.map.set(
|
|
75
|
+
const s = this.normalize(e);
|
|
76
|
+
this.map.set(s.id, s);
|
|
56
77
|
}
|
|
57
78
|
}
|
|
58
79
|
add(t) {
|
|
@@ -72,22 +93,25 @@ class _ {
|
|
|
72
93
|
* Events overlapping [start, end). When `resourceId` is supplied (including
|
|
73
94
|
* `null` for unassigned), only events on that resource are returned.
|
|
74
95
|
*/
|
|
75
|
-
inRange(t, e,
|
|
76
|
-
return this.all().filter((
|
|
96
|
+
inRange(t, e, s) {
|
|
97
|
+
return this.all().filter((i) => s !== void 0 && i.resourceId !== s ? !1 : i.start.isBefore(e) && i.end.isAfter(t));
|
|
77
98
|
}
|
|
78
99
|
}
|
|
79
|
-
class
|
|
100
|
+
class W {
|
|
80
101
|
constructor(t = "group", e = "order") {
|
|
81
102
|
this.groupField = t, this.orderField = e, this.list = [];
|
|
82
103
|
}
|
|
83
104
|
normalize(t) {
|
|
84
|
-
const e = t[this.groupField],
|
|
105
|
+
const e = t[this.groupField], s = t[this.orderField], i = /* @__PURE__ */ new Set(["id", "title", "group", "order", "businessHours", "extendedProps", this.groupField, this.orderField]), n = {};
|
|
106
|
+
for (const o of Object.keys(t))
|
|
107
|
+
i.has(o) || (n[o] = t[o]);
|
|
85
108
|
return {
|
|
86
109
|
id: String(t.id),
|
|
87
110
|
title: t.title ?? "",
|
|
88
111
|
group: e != null ? String(e) : null,
|
|
89
|
-
order: typeof
|
|
90
|
-
|
|
112
|
+
order: typeof s == "number" ? s : 0,
|
|
113
|
+
businessHours: Array.isArray(t.businessHours) ? t.businessHours : [],
|
|
114
|
+
extendedProps: { ...n, ...t.extendedProps ?? {} },
|
|
91
115
|
raw: t
|
|
92
116
|
};
|
|
93
117
|
}
|
|
@@ -115,22 +139,22 @@ class X {
|
|
|
115
139
|
*/
|
|
116
140
|
grouped() {
|
|
117
141
|
const t = [], e = /* @__PURE__ */ new Map();
|
|
118
|
-
for (const
|
|
119
|
-
let
|
|
120
|
-
|
|
142
|
+
for (const s of this.ordered()) {
|
|
143
|
+
let i = e.get(s.group);
|
|
144
|
+
i === void 0 && (i = t.length, e.set(s.group, i), t.push({ group: s.group, resources: [] })), t[i].resources.push(s);
|
|
121
145
|
}
|
|
122
146
|
return t;
|
|
123
147
|
}
|
|
124
148
|
}
|
|
125
|
-
function
|
|
126
|
-
const t = [...
|
|
149
|
+
function $(u) {
|
|
150
|
+
const t = [...u].sort(
|
|
127
151
|
(o, r) => o.start.valueOf() - r.start.valueOf() || r.end.valueOf() - o.end.valueOf()
|
|
128
152
|
), e = [];
|
|
129
|
-
let
|
|
130
|
-
const
|
|
131
|
-
if (
|
|
153
|
+
let s = [], i = -1 / 0;
|
|
154
|
+
const n = () => {
|
|
155
|
+
if (s.length === 0) return;
|
|
132
156
|
const o = [];
|
|
133
|
-
for (const c of
|
|
157
|
+
for (const c of s) {
|
|
134
158
|
let a = !1;
|
|
135
159
|
for (const l of o)
|
|
136
160
|
if (l[l.length - 1].end.valueOf() <= c.start.valueOf()) {
|
|
@@ -143,44 +167,44 @@ function I(p) {
|
|
|
143
167
|
o.forEach((c, a) => {
|
|
144
168
|
for (const l of c)
|
|
145
169
|
e.push({ event: l, col: a, cols: r, left: a / r, width: 1 / r });
|
|
146
|
-
}),
|
|
170
|
+
}), s = [], i = -1 / 0;
|
|
147
171
|
};
|
|
148
172
|
for (const o of t)
|
|
149
|
-
|
|
150
|
-
return
|
|
173
|
+
s.length > 0 && o.start.valueOf() >= i && n(), s.push(o), i = Math.max(i, o.end.valueOf());
|
|
174
|
+
return n(), e;
|
|
151
175
|
}
|
|
152
|
-
function w(
|
|
153
|
-
const e = t.threshold ?? 4,
|
|
154
|
-
let
|
|
176
|
+
function w(u, t) {
|
|
177
|
+
const e = t.threshold ?? 4, s = u.clientX, i = u.clientY;
|
|
178
|
+
let n = !1;
|
|
155
179
|
const o = (c) => {
|
|
156
|
-
var
|
|
157
|
-
const a = c, l = a.clientX -
|
|
158
|
-
!
|
|
180
|
+
var p, m;
|
|
181
|
+
const a = c, l = a.clientX - s, d = a.clientY - i;
|
|
182
|
+
!n && Math.hypot(l, d) < e || (n || (n = !0, (p = t.onStart) == null || p.call(t, a)), (m = t.onMove) == null || m.call(t, { dx: l, dy: d, moved: !0, event: a }));
|
|
159
183
|
}, r = (c) => {
|
|
160
184
|
var l;
|
|
161
185
|
window.removeEventListener("pointermove", o), window.removeEventListener("pointerup", r), window.removeEventListener("pointercancel", r);
|
|
162
186
|
const a = c;
|
|
163
187
|
(l = t.onEnd) == null || l.call(t, {
|
|
164
|
-
dx: a.clientX -
|
|
165
|
-
dy: a.clientY -
|
|
166
|
-
moved:
|
|
188
|
+
dx: a.clientX - s,
|
|
189
|
+
dy: a.clientY - i,
|
|
190
|
+
moved: n,
|
|
167
191
|
event: a
|
|
168
192
|
});
|
|
169
193
|
};
|
|
170
194
|
window.addEventListener("pointermove", o), window.addEventListener("pointerup", r), window.addEventListener("pointercancel", r);
|
|
171
195
|
}
|
|
172
|
-
function x(
|
|
173
|
-
return t <= 0 ?
|
|
196
|
+
function x(u, t) {
|
|
197
|
+
return t <= 0 ? u : Math.round(u / t) * t;
|
|
174
198
|
}
|
|
175
|
-
function h(
|
|
176
|
-
const e = document.createElement(
|
|
199
|
+
function h(u, t) {
|
|
200
|
+
const e = document.createElement(u);
|
|
177
201
|
return e.className = t, e;
|
|
178
202
|
}
|
|
179
|
-
function
|
|
180
|
-
return Math.max(t, Math.min(e,
|
|
203
|
+
function f(u, t, e) {
|
|
204
|
+
return Math.max(t, Math.min(e, u));
|
|
181
205
|
}
|
|
182
206
|
const E = 24;
|
|
183
|
-
class
|
|
207
|
+
class q {
|
|
184
208
|
constructor(t, e) {
|
|
185
209
|
this.cal = t, this.root = e, this.nowLine = null;
|
|
186
210
|
}
|
|
@@ -198,7 +222,7 @@ class F {
|
|
|
198
222
|
return { start: t.startOf("day"), end: t.endOf("day") };
|
|
199
223
|
}
|
|
200
224
|
title() {
|
|
201
|
-
return
|
|
225
|
+
return A(
|
|
202
226
|
this.cal.date,
|
|
203
227
|
{ weekday: "long", day: "numeric", month: "long", year: "numeric" },
|
|
204
228
|
this.localeTag(),
|
|
@@ -212,13 +236,19 @@ class F {
|
|
|
212
236
|
e.style.height = `${this.contentHeight}px`;
|
|
213
237
|
for (let i = t.min; i <= t.max; i += t.labelInterval) {
|
|
214
238
|
const n = h("div", "zc-axis-label");
|
|
215
|
-
n.style.top = `${(i - t.min) * this.pxPerMinute}px`, n.textContent =
|
|
239
|
+
n.style.top = `${(i - t.min) * this.pxPerMinute}px`, n.textContent = I(i), e.appendChild(n);
|
|
216
240
|
}
|
|
217
241
|
this.content = h("div", "zc-col"), this.content.style.height = `${this.contentHeight}px`;
|
|
218
242
|
for (let i = 0; i <= t.slots; i++) {
|
|
219
243
|
const n = h("div", "zc-slot-line");
|
|
220
244
|
i * t.duration % t.labelInterval === 0 && n.classList.add("zc-slot-major"), n.style.top = `${i * E}px`, this.content.appendChild(n);
|
|
221
245
|
}
|
|
246
|
+
const s = this.cal.businessHours;
|
|
247
|
+
if (s.length)
|
|
248
|
+
for (const [i, n] of R(P(this.cal.date.day(), s), t.min, t.max)) {
|
|
249
|
+
const o = h("div", "zc-nonbusiness-fill");
|
|
250
|
+
o.style.top = `${(i - t.min) * this.pxPerMinute}px`, o.style.height = `${(n - i) * this.pxPerMinute}px`, this.content.appendChild(o);
|
|
251
|
+
}
|
|
222
252
|
this.grid.appendChild(e), this.grid.appendChild(this.content), this.root.appendChild(this.grid), this.bindSelect(), this.renderEvents();
|
|
223
253
|
}
|
|
224
254
|
/** Events to lay out in this column. Subclasses scope this by resource. */
|
|
@@ -228,11 +258,11 @@ class F {
|
|
|
228
258
|
}
|
|
229
259
|
renderEvents() {
|
|
230
260
|
if (!this.content) return;
|
|
231
|
-
this.content.querySelectorAll(".zc-event").forEach((
|
|
232
|
-
const t = this.cal.axis, e =
|
|
233
|
-
for (const
|
|
234
|
-
const
|
|
235
|
-
d.dataset.eventId =
|
|
261
|
+
this.content.querySelectorAll(".zc-event").forEach((s) => s.remove());
|
|
262
|
+
const t = this.cal.axis, e = $(this.eventsFor());
|
|
263
|
+
for (const s of e) {
|
|
264
|
+
const i = s.event, n = g(i.start), o = g(i.end) || t.max, r = f(n, t.min, t.max), c = f(o, t.min, t.max), a = (r - t.min) * this.pxPerMinute, l = Math.max(E - 2, (c - r) * this.pxPerMinute), d = h("div", "zc-event");
|
|
265
|
+
d.dataset.eventId = i.id, d.style.top = `${a}px`, d.style.height = `${l}px`, d.style.left = `calc(${s.left * 100}% + 2px)`, d.style.width = `calc(${s.width * 100}% - 4px)`, i.color && d.style.setProperty("--zc-event-bg", i.color), i.textColor && d.style.setProperty("--zc-event-fg", i.textColor), d.appendChild(this.cal.renderEventContent(i)), this.bindBar(d, i), this.content.appendChild(d), this.cal.fireEventMount(i, d);
|
|
236
266
|
}
|
|
237
267
|
this.renderNowIndicator();
|
|
238
268
|
}
|
|
@@ -247,46 +277,46 @@ class F {
|
|
|
247
277
|
/** Wire click, drag-move and resize on an event bar (or just click if read-only). */
|
|
248
278
|
bindBar(t, e) {
|
|
249
279
|
if (this.cal.bindContextMenu(t, e), !this.cal.editable) {
|
|
250
|
-
t.addEventListener("click", (
|
|
280
|
+
t.addEventListener("click", (i) => this.cal.fireEventClick(e, t, i));
|
|
251
281
|
return;
|
|
252
282
|
}
|
|
253
283
|
t.style.cursor = "move";
|
|
254
|
-
const
|
|
255
|
-
t.appendChild(
|
|
256
|
-
if (
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
x(r + (this.minuteAtY(l) - c),
|
|
260
|
-
|
|
261
|
-
|
|
284
|
+
const s = h("div", "zc-resize-handle zc-resize-s");
|
|
285
|
+
t.appendChild(s), s.addEventListener("pointerdown", (i) => this.beginResize(i, t, e)), t.addEventListener("pointerdown", (i) => {
|
|
286
|
+
if (i.button !== 0 || i.target.closest(".zc-resize-handle")) return;
|
|
287
|
+
i.preventDefault();
|
|
288
|
+
const n = this.cal.axis, o = e.end.diff(e.start, "minute"), r = g(e.start), c = this.minuteAtY(i.clientY), a = (l) => f(
|
|
289
|
+
x(r + (this.minuteAtY(l) - c), n.duration),
|
|
290
|
+
n.min,
|
|
291
|
+
n.max - o
|
|
262
292
|
);
|
|
263
|
-
w(
|
|
293
|
+
w(i, {
|
|
264
294
|
onStart: () => t.classList.add("zc-dragging"),
|
|
265
295
|
onMove: ({ event: l }) => {
|
|
266
|
-
t.style.top = `${(a(l.clientY) -
|
|
296
|
+
t.style.top = `${(a(l.clientY) - n.min) * this.pxPerMinute}px`;
|
|
267
297
|
},
|
|
268
298
|
onEnd: ({ moved: l, event: d }) => {
|
|
269
299
|
if (t.classList.remove("zc-dragging"), !l) {
|
|
270
300
|
this.cal.fireEventClick(e, t, d);
|
|
271
301
|
return;
|
|
272
302
|
}
|
|
273
|
-
const
|
|
274
|
-
this.cal.commitEventChange(e,
|
|
303
|
+
const p = this.timeAt(a(d.clientY));
|
|
304
|
+
this.cal.commitEventChange(e, p, p.add(o, "minute"), e.resourceId);
|
|
275
305
|
}
|
|
276
306
|
});
|
|
277
307
|
});
|
|
278
308
|
}
|
|
279
|
-
beginResize(t, e,
|
|
309
|
+
beginResize(t, e, s) {
|
|
280
310
|
if (t.button !== 0) return;
|
|
281
311
|
t.stopPropagation(), t.preventDefault();
|
|
282
|
-
const
|
|
312
|
+
const i = this.cal.axis, n = g(s.start), o = (r) => f(x(this.minuteAtY(r), i.duration), n + i.duration, i.max);
|
|
283
313
|
w(t, {
|
|
284
314
|
onStart: () => e.classList.add("zc-dragging"),
|
|
285
315
|
onMove: ({ event: r }) => {
|
|
286
|
-
e.style.height = `${(o(r.clientY) -
|
|
316
|
+
e.style.height = `${(o(r.clientY) - n) * this.pxPerMinute}px`;
|
|
287
317
|
},
|
|
288
318
|
onEnd: ({ moved: r, event: c }) => {
|
|
289
|
-
e.classList.remove("zc-dragging"), r && this.cal.commitEventChange(
|
|
319
|
+
e.classList.remove("zc-dragging"), r && this.cal.commitEventChange(s, s.start, this.timeAt(o(c.clientY)), s.resourceId);
|
|
290
320
|
}
|
|
291
321
|
});
|
|
292
322
|
}
|
|
@@ -294,37 +324,37 @@ class F {
|
|
|
294
324
|
!this.cal.selectable || !this.content || this.content.addEventListener("pointerdown", (t) => {
|
|
295
325
|
if (t.button !== 0 || t.target.closest(".zc-event")) return;
|
|
296
326
|
t.preventDefault();
|
|
297
|
-
const e = this.cal.axis,
|
|
298
|
-
this.content.appendChild(
|
|
299
|
-
const
|
|
300
|
-
const r =
|
|
301
|
-
|
|
327
|
+
const e = this.cal.axis, s = f(x(this.minuteAtY(t.clientY), e.duration), e.min, e.max), i = h("div", "zc-select-box");
|
|
328
|
+
this.content.appendChild(i);
|
|
329
|
+
const n = (o) => {
|
|
330
|
+
const r = f(x(this.minuteAtY(o), e.duration), e.min, e.max), c = Math.min(s, r), a = Math.max(s, r);
|
|
331
|
+
i.style.top = `${(c - e.min) * this.pxPerMinute}px`, i.style.height = `${(a - c) * this.pxPerMinute}px`;
|
|
302
332
|
};
|
|
303
333
|
w(t, {
|
|
304
|
-
onMove: ({ event: o }) =>
|
|
334
|
+
onMove: ({ event: o }) => n(o.clientY),
|
|
305
335
|
onEnd: ({ moved: o, event: r }) => {
|
|
306
|
-
if (
|
|
307
|
-
const c =
|
|
308
|
-
let a = Math.min(
|
|
336
|
+
if (i.remove(), !o) return;
|
|
337
|
+
const c = f(x(this.minuteAtY(r.clientY), e.duration), e.min, e.max);
|
|
338
|
+
let a = Math.min(s, c), l = Math.max(s, c);
|
|
309
339
|
l <= a && (l = Math.min(a + e.duration, e.max)), !(l <= a) && this.cal.commitSelect(this.timeAt(a), this.timeAt(l), null, r);
|
|
310
340
|
}
|
|
311
341
|
});
|
|
312
342
|
});
|
|
313
343
|
}
|
|
314
344
|
renderNowIndicator() {
|
|
315
|
-
var
|
|
316
|
-
if ((
|
|
345
|
+
var i;
|
|
346
|
+
if ((i = this.nowLine) == null || i.remove(), this.nowLine = null, !this.cal.options.nowIndicator || !this.content) return;
|
|
317
347
|
const t = this.cal.now();
|
|
318
348
|
if (!t.isSame(this.cal.date, "day")) return;
|
|
319
|
-
const e = this.cal.axis,
|
|
320
|
-
|
|
349
|
+
const e = this.cal.axis, s = g(t);
|
|
350
|
+
s < e.min || s > e.max || (this.nowLine = h("div", "zc-now-indicator"), this.nowLine.style.top = `${(s - e.min) * this.pxPerMinute}px`, this.content.appendChild(this.nowLine));
|
|
321
351
|
}
|
|
322
352
|
unmount() {
|
|
323
353
|
var t;
|
|
324
354
|
(t = this.grid) == null || t.remove(), this.grid = void 0, this.content = void 0, this.nowLine = null;
|
|
325
355
|
}
|
|
326
356
|
}
|
|
327
|
-
class
|
|
357
|
+
class G {
|
|
328
358
|
constructor(t, e) {
|
|
329
359
|
this.cal = t, this.root = e, this.nowLine = null, this.cols = [];
|
|
330
360
|
}
|
|
@@ -342,7 +372,7 @@ class V {
|
|
|
342
372
|
return { start: t.startOf("day"), end: t.endOf("day") };
|
|
343
373
|
}
|
|
344
374
|
title() {
|
|
345
|
-
return
|
|
375
|
+
return A(
|
|
346
376
|
this.cal.date,
|
|
347
377
|
{ weekday: "long", day: "numeric", month: "long", year: "numeric" },
|
|
348
378
|
this.localeTag(),
|
|
@@ -352,28 +382,28 @@ class V {
|
|
|
352
382
|
// ---- mount ---------------------------------------------------------------
|
|
353
383
|
mount() {
|
|
354
384
|
this.rootEl = h("div", "zc-rg");
|
|
355
|
-
const t = this.cal.resources.grouped(), e = t.flatMap((
|
|
356
|
-
this.rootEl.appendChild(this.buildHead(t,
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
for (const
|
|
385
|
+
const t = this.cal.resources.grouped(), e = t.flatMap((n) => n.resources), s = t.length > 1 || t.some((n) => n.group !== null);
|
|
386
|
+
this.rootEl.appendChild(this.buildHead(t, s));
|
|
387
|
+
const i = h("div", "zc-rg-canvas");
|
|
388
|
+
i.style.height = `${this.contentHeight}px`, i.appendChild(this.buildAxis()), this.colsEl = h("div", "zc-rg-cols"), this.cols = [];
|
|
389
|
+
for (const n of e) {
|
|
360
390
|
const o = h("div", "zc-rg-col");
|
|
361
|
-
o.dataset.resourceId =
|
|
391
|
+
o.dataset.resourceId = n.id, this.buildSlotLines(o), this.buildNonBusiness(o, n), this.bindColSelect(o, n), this.colsEl.appendChild(o), this.cols.push({ resource: n, content: o });
|
|
362
392
|
}
|
|
363
|
-
|
|
393
|
+
i.appendChild(this.colsEl), this.rootEl.appendChild(i), this.root.appendChild(this.rootEl), this.renderEvents();
|
|
364
394
|
}
|
|
365
395
|
buildHead(t, e) {
|
|
366
396
|
var r, c;
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
const
|
|
397
|
+
const s = h("div", "zc-rg-head"), i = h("div", "zc-rg-corner");
|
|
398
|
+
s.appendChild(i);
|
|
399
|
+
const n = h("div", "zc-rg-head-cols");
|
|
370
400
|
if (e) {
|
|
371
401
|
const a = h("div", "zc-rg-group-row");
|
|
372
402
|
for (const l of t) {
|
|
373
403
|
const d = h("div", "zc-rg-group-band");
|
|
374
404
|
d.style.flex = `${l.resources.length} 1 0`, d.textContent = l.group ?? "", a.appendChild(d);
|
|
375
405
|
}
|
|
376
|
-
|
|
406
|
+
n.appendChild(a);
|
|
377
407
|
}
|
|
378
408
|
const o = h("div", "zc-rg-label-row");
|
|
379
409
|
for (const a of t.flatMap((l) => l.resources)) {
|
|
@@ -382,46 +412,55 @@ class V {
|
|
|
382
412
|
const d = (c = (r = this.cal.options).renderResource) == null ? void 0 : c.call(r, a);
|
|
383
413
|
d != null ? typeof d == "string" ? l.innerHTML = d : l.appendChild(d) : l.textContent = a.title, o.appendChild(l);
|
|
384
414
|
}
|
|
385
|
-
return
|
|
415
|
+
return n.appendChild(o), s.appendChild(n), s;
|
|
386
416
|
}
|
|
387
417
|
buildAxis() {
|
|
388
418
|
const t = h("div", "zc-axis zc-rg-axis");
|
|
389
419
|
t.style.height = `${this.contentHeight}px`;
|
|
390
420
|
const e = this.cal.axis;
|
|
391
|
-
for (let
|
|
392
|
-
const
|
|
393
|
-
|
|
421
|
+
for (let s = e.min; s <= e.max; s += e.labelInterval) {
|
|
422
|
+
const i = h("div", "zc-axis-label");
|
|
423
|
+
i.style.top = `${(s - e.min) * this.pxPerMinute}px`, i.textContent = I(s), t.appendChild(i);
|
|
394
424
|
}
|
|
395
425
|
return t;
|
|
396
426
|
}
|
|
427
|
+
buildNonBusiness(t, e) {
|
|
428
|
+
const s = e.businessHours.length ? e.businessHours : this.cal.businessHours;
|
|
429
|
+
if (!s.length) return;
|
|
430
|
+
const i = this.cal.axis;
|
|
431
|
+
for (const [n, o] of R(P(this.cal.date.day(), s), i.min, i.max)) {
|
|
432
|
+
const r = h("div", "zc-nonbusiness-fill");
|
|
433
|
+
r.style.top = `${(n - i.min) * this.pxPerMinute}px`, r.style.height = `${(o - n) * this.pxPerMinute}px`, t.appendChild(r);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
397
436
|
buildSlotLines(t) {
|
|
398
437
|
const e = this.cal.axis;
|
|
399
|
-
for (let
|
|
400
|
-
const
|
|
401
|
-
|
|
438
|
+
for (let s = 0; s <= e.slots; s++) {
|
|
439
|
+
const i = h("div", "zc-slot-line");
|
|
440
|
+
s * e.duration % e.labelInterval === 0 && i.classList.add("zc-slot-major"), i.style.top = `${s * E}px`, t.appendChild(i);
|
|
402
441
|
}
|
|
403
442
|
}
|
|
404
443
|
// ---- events --------------------------------------------------------------
|
|
405
444
|
renderEvents() {
|
|
406
445
|
if (!this.colsEl) return;
|
|
407
446
|
const t = this.range(), e = this.cal.axis;
|
|
408
|
-
for (const { resource:
|
|
409
|
-
|
|
410
|
-
const
|
|
411
|
-
for (const o of
|
|
412
|
-
const r = o.event, c =
|
|
413
|
-
v.dataset.eventId = r.id, v.style.top = `${
|
|
447
|
+
for (const { resource: s, content: i } of this.cols) {
|
|
448
|
+
i.querySelectorAll(".zc-event").forEach((o) => o.remove());
|
|
449
|
+
const n = $(this.cal.events.inRange(t.start, t.end, s.id));
|
|
450
|
+
for (const o of n) {
|
|
451
|
+
const r = o.event, c = g(r.start), a = g(r.end) || e.max, l = f(c, e.min, e.max), d = f(a, e.min, e.max), p = (l - e.min) * this.pxPerMinute, m = Math.max(E - 2, (d - l) * this.pxPerMinute), v = h("div", "zc-event");
|
|
452
|
+
v.dataset.eventId = r.id, v.style.top = `${p}px`, v.style.height = `${m}px`, v.style.left = `calc(${o.left * 100}% + 2px)`, v.style.width = `calc(${o.width * 100}% - 4px)`, r.color && v.style.setProperty("--zc-event-bg", r.color), r.textColor && v.style.setProperty("--zc-event-fg", r.textColor), v.appendChild(this.cal.renderEventContent(r)), this.bindBar(v, r), i.appendChild(v), this.cal.fireEventMount(r, v);
|
|
414
453
|
}
|
|
415
454
|
}
|
|
416
455
|
this.renderNowIndicator();
|
|
417
456
|
}
|
|
418
457
|
renderNowIndicator() {
|
|
419
|
-
var
|
|
420
|
-
if ((
|
|
458
|
+
var i;
|
|
459
|
+
if ((i = this.nowLine) == null || i.remove(), this.nowLine = null, !this.cal.options.nowIndicator || !this.colsEl) return;
|
|
421
460
|
const t = this.cal.now();
|
|
422
461
|
if (!t.isSame(this.cal.date, "day")) return;
|
|
423
|
-
const e = this.cal.axis,
|
|
424
|
-
|
|
462
|
+
const e = this.cal.axis, s = g(t);
|
|
463
|
+
s < e.min || s > e.max || (this.nowLine = h("div", "zc-now-indicator zc-rg-now"), this.nowLine.style.top = `${(s - e.min) * this.pxPerMinute}px`, this.colsEl.appendChild(this.nowLine));
|
|
425
464
|
}
|
|
426
465
|
// ---- interaction ---------------------------------------------------------
|
|
427
466
|
timeAt(t) {
|
|
@@ -433,75 +472,87 @@ class V {
|
|
|
433
472
|
}
|
|
434
473
|
/** The resource column under the pointer (bar ignored for hit-testing). */
|
|
435
474
|
resourceIdAt(t, e) {
|
|
436
|
-
const
|
|
475
|
+
const s = e.style.pointerEvents;
|
|
437
476
|
e.style.pointerEvents = "none";
|
|
438
|
-
const
|
|
439
|
-
e.style.pointerEvents =
|
|
440
|
-
const
|
|
441
|
-
return
|
|
477
|
+
const i = document.elementFromPoint(t.clientX, t.clientY);
|
|
478
|
+
e.style.pointerEvents = s;
|
|
479
|
+
const n = i == null ? void 0 : i.closest(".zc-rg-col[data-resource-id]");
|
|
480
|
+
return n ? n.dataset.resourceId ?? null : void 0;
|
|
481
|
+
}
|
|
482
|
+
highlightCol(t, e) {
|
|
483
|
+
var n;
|
|
484
|
+
this.clearHighlight();
|
|
485
|
+
const s = e.style.pointerEvents;
|
|
486
|
+
e.style.pointerEvents = "none";
|
|
487
|
+
const i = document.elementFromPoint(t.clientX, t.clientY);
|
|
488
|
+
e.style.pointerEvents = s, (n = i == null ? void 0 : i.closest(".zc-rg-col[data-resource-id]")) == null || n.classList.add("zc-drop-target");
|
|
489
|
+
}
|
|
490
|
+
clearHighlight() {
|
|
491
|
+
var t;
|
|
492
|
+
(t = this.colsEl) == null || t.querySelectorAll(".zc-drop-target").forEach((e) => e.classList.remove("zc-drop-target"));
|
|
442
493
|
}
|
|
443
494
|
bindBar(t, e) {
|
|
444
495
|
if (this.cal.bindContextMenu(t, e), !this.cal.editable) {
|
|
445
|
-
t.addEventListener("click", (
|
|
496
|
+
t.addEventListener("click", (i) => this.cal.fireEventClick(e, t, i));
|
|
446
497
|
return;
|
|
447
498
|
}
|
|
448
499
|
t.style.cursor = "move";
|
|
449
|
-
const
|
|
450
|
-
t.appendChild(
|
|
451
|
-
if (
|
|
452
|
-
|
|
453
|
-
const
|
|
454
|
-
x(r + (this.minuteAtY(l) - c),
|
|
455
|
-
|
|
456
|
-
|
|
500
|
+
const s = h("div", "zc-resize-handle zc-resize-s");
|
|
501
|
+
t.appendChild(s), s.addEventListener("pointerdown", (i) => this.beginResize(i, t, e)), t.addEventListener("pointerdown", (i) => {
|
|
502
|
+
if (i.button !== 0 || i.target.closest(".zc-resize-handle")) return;
|
|
503
|
+
i.preventDefault();
|
|
504
|
+
const n = this.cal.axis, o = e.end.diff(e.start, "minute"), r = g(e.start), c = this.minuteAtY(i.clientY), a = (l) => f(
|
|
505
|
+
x(r + (this.minuteAtY(l) - c), n.duration),
|
|
506
|
+
n.min,
|
|
507
|
+
n.max - o
|
|
457
508
|
);
|
|
458
|
-
w(
|
|
509
|
+
w(i, {
|
|
459
510
|
onStart: () => t.classList.add("zc-dragging"),
|
|
460
511
|
onMove: ({ event: l }) => {
|
|
461
|
-
t.style.top = `${(a(l.clientY) -
|
|
512
|
+
t.style.top = `${(a(l.clientY) - n.min) * this.pxPerMinute}px`, this.highlightCol(l, t);
|
|
462
513
|
},
|
|
463
514
|
onEnd: ({ moved: l, event: d }) => {
|
|
464
|
-
if (t.classList.remove("zc-dragging"), !l) {
|
|
515
|
+
if (t.classList.remove("zc-dragging"), this.clearHighlight(), !l) {
|
|
465
516
|
this.cal.fireEventClick(e, t, d);
|
|
466
517
|
return;
|
|
467
518
|
}
|
|
468
|
-
const
|
|
469
|
-
this.cal.commitEventChange(e,
|
|
519
|
+
const p = this.timeAt(a(d.clientY)), m = this.resourceIdAt(d, t) ?? e.resourceId;
|
|
520
|
+
this.cal.commitEventChange(e, p, p.add(o, "minute"), m);
|
|
470
521
|
}
|
|
471
522
|
});
|
|
472
523
|
});
|
|
473
524
|
}
|
|
474
|
-
beginResize(t, e,
|
|
525
|
+
beginResize(t, e, s) {
|
|
475
526
|
if (t.button !== 0) return;
|
|
476
527
|
t.stopPropagation(), t.preventDefault();
|
|
477
|
-
const
|
|
528
|
+
const i = this.cal.axis, n = g(s.start), o = (r) => f(x(this.minuteAtY(r), i.duration), n + i.duration, i.max);
|
|
478
529
|
w(t, {
|
|
479
530
|
onStart: () => e.classList.add("zc-dragging"),
|
|
480
531
|
onMove: ({ event: r }) => {
|
|
481
|
-
e.style.height = `${(o(r.clientY) -
|
|
532
|
+
e.style.height = `${(o(r.clientY) - n) * this.pxPerMinute}px`;
|
|
482
533
|
},
|
|
483
534
|
onEnd: ({ moved: r, event: c }) => {
|
|
484
|
-
e.classList.remove("zc-dragging"), r && this.cal.commitEventChange(
|
|
535
|
+
e.classList.remove("zc-dragging"), r && this.cal.commitEventChange(s, s.start, this.timeAt(o(c.clientY)), s.resourceId);
|
|
485
536
|
}
|
|
486
537
|
});
|
|
487
538
|
}
|
|
488
539
|
bindColSelect(t, e) {
|
|
489
|
-
this.cal.selectable && t.addEventListener("pointerdown", (
|
|
490
|
-
if (
|
|
491
|
-
|
|
492
|
-
const
|
|
540
|
+
this.cal.selectable && t.addEventListener("pointerdown", (s) => {
|
|
541
|
+
if (s.button !== 0 || s.target.closest(".zc-event")) return;
|
|
542
|
+
s.preventDefault();
|
|
543
|
+
const i = this.cal.axis, n = f(x(this.minuteAtY(s.clientY), i.duration), i.min, i.max), o = h("div", "zc-select-box zc-rg-select");
|
|
493
544
|
t.appendChild(o);
|
|
494
545
|
const r = (c) => {
|
|
495
|
-
const a =
|
|
496
|
-
o.style.top = `${(l -
|
|
546
|
+
const a = f(x(this.minuteAtY(c), i.duration), i.min, i.max), l = Math.min(n, a), d = Math.max(n, a);
|
|
547
|
+
o.style.top = `${(l - i.min) * this.pxPerMinute}px`, o.style.height = `${(d - l) * this.pxPerMinute}px`;
|
|
497
548
|
};
|
|
498
|
-
w(
|
|
549
|
+
w(s, {
|
|
499
550
|
onMove: ({ event: c }) => r(c.clientY),
|
|
500
551
|
onEnd: ({ moved: c, event: a }) => {
|
|
501
552
|
if (o.remove(), !c) return;
|
|
502
|
-
const l =
|
|
503
|
-
let d = Math.min(
|
|
504
|
-
|
|
553
|
+
const l = f(x(this.minuteAtY(a.clientY), i.duration), i.min, i.max);
|
|
554
|
+
let d = Math.min(n, l), p = Math.max(n, l);
|
|
555
|
+
p <= d && (p = Math.min(d + i.duration, i.max)), !(p <= d) && this.cal.commitSelect(this.timeAt(d), this.timeAt(p), e, a);
|
|
505
556
|
}
|
|
506
557
|
});
|
|
507
558
|
});
|
|
@@ -511,14 +562,14 @@ class V {
|
|
|
511
562
|
(t = this.rootEl) == null || t.remove(), this.rootEl = void 0, this.colsEl = void 0, this.nowLine = null, this.cols = [];
|
|
512
563
|
}
|
|
513
564
|
}
|
|
514
|
-
const
|
|
515
|
-
class
|
|
565
|
+
const B = 38, D = 26, U = 48, k = 4, j = 90, Z = 14;
|
|
566
|
+
class J {
|
|
516
567
|
constructor(t, e) {
|
|
517
568
|
this.cal = t, this.root = e;
|
|
518
569
|
}
|
|
519
570
|
// ---- geometry ------------------------------------------------------------
|
|
520
571
|
get pxPerMinute() {
|
|
521
|
-
return
|
|
572
|
+
return j / 60;
|
|
522
573
|
}
|
|
523
574
|
get width() {
|
|
524
575
|
return this.cal.axis.totalMinutes * this.pxPerMinute;
|
|
@@ -531,7 +582,7 @@ class q {
|
|
|
531
582
|
return { start: t.startOf("day"), end: t.endOf("day") };
|
|
532
583
|
}
|
|
533
584
|
title() {
|
|
534
|
-
return
|
|
585
|
+
return A(
|
|
535
586
|
this.cal.date,
|
|
536
587
|
{ weekday: "long", day: "numeric", month: "long", year: "numeric" },
|
|
537
588
|
this.localeTag(),
|
|
@@ -544,92 +595,110 @@ class q {
|
|
|
544
595
|
const t = (e = this.cal.options.resourceArea) == null ? void 0 : e.columns;
|
|
545
596
|
return t && t.length ? t : [{ field: "title", header: "" }];
|
|
546
597
|
}
|
|
547
|
-
applyWidth(t, e,
|
|
598
|
+
applyWidth(t, e, s = !0) {
|
|
548
599
|
if (e != null) {
|
|
549
|
-
const
|
|
550
|
-
t.style.flex = `0 0 ${
|
|
551
|
-
} else
|
|
600
|
+
const i = typeof e == "number" ? `${e}px` : e;
|
|
601
|
+
t.style.flex = `0 0 ${i}`, t.style.width = i;
|
|
602
|
+
} else s && (t.style.flex = "1 1 0");
|
|
552
603
|
}
|
|
553
604
|
// ---- mount ---------------------------------------------------------------
|
|
554
605
|
mount() {
|
|
555
|
-
var
|
|
606
|
+
var n, o;
|
|
556
607
|
this.rootEl = h("div", "zc-timeline");
|
|
557
608
|
const t = h("div", "zc-tl-resource-area");
|
|
558
|
-
this.applyWidth(t, ((
|
|
609
|
+
this.applyWidth(t, ((n = this.cal.options.resourceArea) == null ? void 0 : n.width) ?? "25%", !1), ((o = this.cal.options.resourceArea) == null ? void 0 : o.width) == null && (t.style.flex = "0 0 25%");
|
|
559
610
|
const e = h("div", "zc-tl-resource-head");
|
|
560
|
-
e.style.height = `${
|
|
611
|
+
e.style.height = `${B}px`;
|
|
561
612
|
for (const r of this.columns()) {
|
|
562
613
|
const c = h("div", "zc-tl-col-head");
|
|
563
614
|
this.applyWidth(c, r.width), c.textContent = r.header ?? "", e.appendChild(c);
|
|
564
615
|
}
|
|
565
616
|
this.resourceBody = h("div", "zc-tl-resource-body"), this.resourceRows = h("div", "zc-tl-resource-rows"), this.resourceBody.appendChild(this.resourceRows), t.append(e, this.resourceBody);
|
|
566
|
-
const
|
|
567
|
-
this.timeHead = h("div", "zc-tl-time-head"), this.timeHead.style.height = `${
|
|
568
|
-
const
|
|
569
|
-
|
|
617
|
+
const s = h("div", "zc-tl-time-area");
|
|
618
|
+
this.timeHead = h("div", "zc-tl-time-head"), this.timeHead.style.height = `${B}px`, this.buildAxisHeader(this.timeHead), this.timeBody = h("div", "zc-tl-time-body");
|
|
619
|
+
const i = h("div", "zc-tl-time-canvas");
|
|
620
|
+
i.style.width = `${this.width}px`, this.overlay = h("div", "zc-tl-overlay"), this.buildOverlayLines(this.overlay), this.rowsEl = h("div", "zc-tl-rows"), i.append(this.overlay, this.rowsEl), this.timeBody.appendChild(i), s.append(this.timeHead, this.timeBody), this.rootEl.append(t, s), this.root.appendChild(this.rootEl), this.onScroll = () => {
|
|
570
621
|
this.resourceBody && this.timeBody && (this.resourceBody.scrollTop = this.timeBody.scrollTop), this.timeHead && this.timeBody && (this.timeHead.scrollLeft = this.timeBody.scrollLeft);
|
|
571
622
|
}, this.timeBody.addEventListener("scroll", this.onScroll, { passive: !0 }), this.relayout();
|
|
572
623
|
}
|
|
573
624
|
buildAxisHeader(t) {
|
|
574
625
|
const e = h("div", "zc-tl-axis");
|
|
575
626
|
e.style.width = `${this.width}px`;
|
|
576
|
-
const
|
|
577
|
-
for (let
|
|
578
|
-
const
|
|
579
|
-
|
|
627
|
+
const s = this.cal.axis;
|
|
628
|
+
for (let i = s.min; i <= s.max; i += s.labelInterval) {
|
|
629
|
+
const n = h("div", "zc-tl-axis-label");
|
|
630
|
+
n.style.left = `${(i - s.min) * this.pxPerMinute}px`, n.textContent = I(i), e.appendChild(n);
|
|
580
631
|
}
|
|
581
632
|
t.appendChild(e);
|
|
582
633
|
}
|
|
583
634
|
buildOverlayLines(t) {
|
|
584
635
|
const e = this.cal.axis;
|
|
585
|
-
for (let
|
|
586
|
-
const
|
|
587
|
-
|
|
636
|
+
for (let s = e.min; s <= e.max; s += e.labelInterval) {
|
|
637
|
+
const i = h("div", "zc-tl-vline");
|
|
638
|
+
i.style.left = `${(s - e.min) * this.pxPerMinute}px`, t.appendChild(i);
|
|
588
639
|
}
|
|
589
640
|
}
|
|
590
641
|
// ---- layout (rows + events) ---------------------------------------------
|
|
591
642
|
renderEvents() {
|
|
592
643
|
this.relayout();
|
|
593
644
|
}
|
|
645
|
+
/** Re-render only the resource-area cells, leaving event bars untouched. */
|
|
646
|
+
renderResources() {
|
|
647
|
+
this.resourceRows && this.resourceRows.querySelectorAll(".zc-tl-resource-row[data-resource-id]").forEach((t) => {
|
|
648
|
+
const e = this.cal.resources.get(t.dataset.resourceId ?? "");
|
|
649
|
+
if (e) {
|
|
650
|
+
t.innerHTML = "";
|
|
651
|
+
for (const s of this.columns()) {
|
|
652
|
+
const i = h("div", "zc-tl-col-cell");
|
|
653
|
+
this.applyWidth(i, s.width), this.fillResourceCell(i, s, e), t.appendChild(i);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
}
|
|
594
658
|
/** Rebuild rows in both panes from the current resources + events. */
|
|
595
659
|
relayout() {
|
|
596
660
|
if (!this.resourceRows || !this.rowsEl) return;
|
|
597
661
|
this.resourceRows.innerHTML = "", this.rowsEl.innerHTML = "";
|
|
598
|
-
const t = this.range(), e = this.cal.resources.grouped(),
|
|
599
|
-
for (const
|
|
600
|
-
|
|
601
|
-
for (const
|
|
602
|
-
const o = this.cal.events.inRange(t.start, t.end,
|
|
603
|
-
this.appendResourceRow(
|
|
662
|
+
const t = this.range(), e = this.cal.resources.grouped(), s = e.length > 1 || e.some((i) => i.group !== null);
|
|
663
|
+
for (const i of e) {
|
|
664
|
+
s && i.group !== null && this.appendGroupRow(i.group);
|
|
665
|
+
for (const n of i.resources) {
|
|
666
|
+
const o = this.cal.events.inRange(t.start, t.end, n.id);
|
|
667
|
+
this.appendResourceRow(n, o);
|
|
604
668
|
}
|
|
605
669
|
}
|
|
606
670
|
this.renderNowIndicator();
|
|
607
671
|
}
|
|
608
672
|
appendGroupRow(t) {
|
|
609
673
|
const e = h("div", "zc-tl-resource-row zc-tl-group-row");
|
|
610
|
-
e.style.height = `${
|
|
611
|
-
const
|
|
612
|
-
|
|
674
|
+
e.style.height = `${D}px`, e.textContent = t, this.resourceRows.appendChild(e);
|
|
675
|
+
const s = h("div", "zc-tl-row zc-tl-group-spacer");
|
|
676
|
+
s.style.height = `${D}px`, this.rowsEl.appendChild(s);
|
|
613
677
|
}
|
|
614
678
|
appendResourceRow(t, e) {
|
|
615
|
-
const
|
|
679
|
+
const s = $(e), i = s.reduce((p, m) => Math.max(p, m.cols), 1), n = this.cal.options.eventMinHeight ?? U, o = i * n + 2 * k, r = n, c = h("div", "zc-tl-resource-row");
|
|
616
680
|
c.style.height = `${o}px`, c.dataset.resourceId = t.id;
|
|
617
|
-
for (const
|
|
618
|
-
const
|
|
619
|
-
this.applyWidth(
|
|
681
|
+
for (const p of this.columns()) {
|
|
682
|
+
const m = h("div", "zc-tl-col-cell");
|
|
683
|
+
this.applyWidth(m, p.width), this.fillResourceCell(m, p, t), c.appendChild(m);
|
|
620
684
|
}
|
|
621
685
|
this.resourceRows.appendChild(c);
|
|
622
686
|
const a = h("div", "zc-tl-row");
|
|
623
687
|
a.style.height = `${o}px`, a.dataset.resourceId = t.id;
|
|
624
|
-
const l = this.cal.axis;
|
|
625
|
-
|
|
626
|
-
const
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
const
|
|
632
|
-
|
|
688
|
+
const l = this.cal.axis, d = t.businessHours.length ? t.businessHours : this.cal.businessHours;
|
|
689
|
+
if (d.length)
|
|
690
|
+
for (const [p, m] of R(P(this.cal.date.day(), d), l.min, l.max)) {
|
|
691
|
+
const v = h("div", "zc-nonbusiness-fill");
|
|
692
|
+
v.style.left = `${(p - l.min) * this.pxPerMinute}px`, v.style.width = `${(m - p) * this.pxPerMinute}px`, a.appendChild(v);
|
|
693
|
+
}
|
|
694
|
+
for (const p of s) {
|
|
695
|
+
const m = p.event, v = g(m.start);
|
|
696
|
+
let z = g(m.end);
|
|
697
|
+
z <= v && (z = l.max);
|
|
698
|
+
const S = f(v, l.min, l.max), H = f(z, l.min, l.max);
|
|
699
|
+
if (H <= l.min || S >= l.max) continue;
|
|
700
|
+
const T = (S - l.min) * this.pxPerMinute, O = Math.max(Z, (H - S) * this.pxPerMinute), N = k + p.col * r, y = h("div", "zc-event zc-tl-event");
|
|
701
|
+
y.dataset.eventId = m.id, y.style.left = `${T}px`, y.style.width = `${Math.min(O, this.width - T)}px`, y.style.top = `${N}px`, y.style.height = `${r - 2}px`, m.color && y.style.setProperty("--zc-event-bg", m.color), m.textColor && y.style.setProperty("--zc-event-fg", m.textColor), y.appendChild(this.cal.renderEventContent(m)), this.bindBar(y, m), a.appendChild(y), this.cal.fireEventMount(m, y);
|
|
633
702
|
}
|
|
634
703
|
this.bindRowSelect(a, t), this.rowsEl.appendChild(a);
|
|
635
704
|
}
|
|
@@ -643,14 +712,14 @@ class q {
|
|
|
643
712
|
}
|
|
644
713
|
/** The resource row currently under the pointer (bar ignored for hit-testing). */
|
|
645
714
|
rowAt(t, e) {
|
|
646
|
-
const
|
|
715
|
+
const s = e.style.pointerEvents;
|
|
647
716
|
e.style.pointerEvents = "none";
|
|
648
|
-
const
|
|
649
|
-
return e.style.pointerEvents =
|
|
717
|
+
const i = document.elementFromPoint(t.clientX, t.clientY);
|
|
718
|
+
return e.style.pointerEvents = s, (i == null ? void 0 : i.closest(".zc-tl-row[data-resource-id]")) ?? null;
|
|
650
719
|
}
|
|
651
720
|
highlightRow(t, e) {
|
|
652
|
-
var
|
|
653
|
-
this.clearHighlight(), (
|
|
721
|
+
var s;
|
|
722
|
+
this.clearHighlight(), (s = this.rowAt(t, e)) == null || s.classList.add("zc-drop-target");
|
|
654
723
|
}
|
|
655
724
|
clearHighlight() {
|
|
656
725
|
var t;
|
|
@@ -658,108 +727,108 @@ class q {
|
|
|
658
727
|
}
|
|
659
728
|
bindBar(t, e) {
|
|
660
729
|
if (this.cal.bindContextMenu(t, e), !this.cal.editable) {
|
|
661
|
-
t.addEventListener("click", (
|
|
730
|
+
t.addEventListener("click", (n) => this.cal.fireEventClick(e, t, n));
|
|
662
731
|
return;
|
|
663
732
|
}
|
|
664
733
|
t.style.cursor = "move";
|
|
665
|
-
const
|
|
666
|
-
t.append(
|
|
667
|
-
if (
|
|
668
|
-
|
|
669
|
-
const o = this.cal.axis, r = e.end.diff(e.start, "minute"), c =
|
|
734
|
+
const s = h("div", "zc-resize-handle zc-resize-w"), i = h("div", "zc-resize-handle zc-resize-e");
|
|
735
|
+
t.append(s, i), s.addEventListener("pointerdown", (n) => this.beginResize(n, t, e, "start")), i.addEventListener("pointerdown", (n) => this.beginResize(n, t, e, "end")), t.addEventListener("pointerdown", (n) => {
|
|
736
|
+
if (n.button !== 0 || n.target.closest(".zc-resize-handle")) return;
|
|
737
|
+
n.preventDefault();
|
|
738
|
+
const o = this.cal.axis, r = e.end.diff(e.start, "minute"), c = g(e.start), a = this.minuteAtX(n.clientX), l = (d) => f(
|
|
670
739
|
x(c + (this.minuteAtX(d) - a), o.duration),
|
|
671
740
|
o.min,
|
|
672
741
|
o.max - r
|
|
673
742
|
);
|
|
674
|
-
w(
|
|
743
|
+
w(n, {
|
|
675
744
|
onStart: () => t.classList.add("zc-dragging"),
|
|
676
745
|
onMove: ({ event: d }) => {
|
|
677
746
|
t.style.left = `${(l(d.clientX) - o.min) * this.pxPerMinute}px`, this.highlightRow(d, t);
|
|
678
747
|
},
|
|
679
|
-
onEnd: ({ moved: d, event:
|
|
748
|
+
onEnd: ({ moved: d, event: p }) => {
|
|
680
749
|
if (t.classList.remove("zc-dragging"), this.clearHighlight(), !d) {
|
|
681
|
-
this.cal.fireEventClick(e, t,
|
|
750
|
+
this.cal.fireEventClick(e, t, p);
|
|
682
751
|
return;
|
|
683
752
|
}
|
|
684
|
-
const
|
|
753
|
+
const m = this.rowAt(p, t), v = m ? m.dataset.resourceId ?? null : e.resourceId, z = this.timeAt(l(p.clientX));
|
|
685
754
|
this.cal.commitEventChange(e, z, z.add(r, "minute"), v);
|
|
686
755
|
}
|
|
687
756
|
});
|
|
688
757
|
});
|
|
689
758
|
}
|
|
690
|
-
beginResize(t, e,
|
|
759
|
+
beginResize(t, e, s, i) {
|
|
691
760
|
if (t.button !== 0) return;
|
|
692
761
|
t.stopPropagation(), t.preventDefault();
|
|
693
|
-
const
|
|
762
|
+
const n = this.cal.axis, o = (r) => f(x(this.minuteAtX(r), n.duration), n.min, n.max);
|
|
694
763
|
w(t, {
|
|
695
764
|
onStart: () => e.classList.add("zc-dragging"),
|
|
696
765
|
onMove: ({ event: r }) => {
|
|
697
766
|
const c = o(r.clientX);
|
|
698
|
-
if (
|
|
699
|
-
const a = Math.max(c,
|
|
700
|
-
e.style.width = `${(a -
|
|
767
|
+
if (i === "end") {
|
|
768
|
+
const a = Math.max(c, g(s.start) + n.duration);
|
|
769
|
+
e.style.width = `${(a - g(s.start)) * this.pxPerMinute}px`;
|
|
701
770
|
} else {
|
|
702
|
-
const a = Math.min(c,
|
|
703
|
-
e.style.left = `${(a -
|
|
771
|
+
const a = Math.min(c, g(s.end) - n.duration);
|
|
772
|
+
e.style.left = `${(a - n.min) * this.pxPerMinute}px`, e.style.width = `${(g(s.end) - a) * this.pxPerMinute}px`;
|
|
704
773
|
}
|
|
705
774
|
},
|
|
706
775
|
onEnd: ({ moved: r, event: c }) => {
|
|
707
776
|
if (e.classList.remove("zc-dragging"), !r) return;
|
|
708
777
|
const a = o(c.clientX);
|
|
709
|
-
if (
|
|
710
|
-
const l = Math.max(a,
|
|
711
|
-
this.cal.commitEventChange(
|
|
778
|
+
if (i === "end") {
|
|
779
|
+
const l = Math.max(a, g(s.start) + n.duration);
|
|
780
|
+
this.cal.commitEventChange(s, s.start, this.timeAt(l), s.resourceId);
|
|
712
781
|
} else {
|
|
713
|
-
const l = Math.min(a,
|
|
714
|
-
this.cal.commitEventChange(
|
|
782
|
+
const l = Math.min(a, g(s.end) - n.duration);
|
|
783
|
+
this.cal.commitEventChange(s, this.timeAt(l), s.end, s.resourceId);
|
|
715
784
|
}
|
|
716
785
|
}
|
|
717
786
|
});
|
|
718
787
|
}
|
|
719
788
|
bindRowSelect(t, e) {
|
|
720
|
-
this.cal.selectable && t.addEventListener("pointerdown", (
|
|
721
|
-
if (
|
|
722
|
-
|
|
723
|
-
const
|
|
789
|
+
this.cal.selectable && t.addEventListener("pointerdown", (s) => {
|
|
790
|
+
if (s.button !== 0 || s.target.closest(".zc-event")) return;
|
|
791
|
+
s.preventDefault();
|
|
792
|
+
const i = this.cal.axis, n = f(x(this.minuteAtX(s.clientX), i.duration), i.min, i.max), o = h("div", "zc-select-box zc-tl-select");
|
|
724
793
|
t.appendChild(o);
|
|
725
794
|
const r = (c) => {
|
|
726
|
-
const a =
|
|
727
|
-
o.style.left = `${(l -
|
|
795
|
+
const a = f(x(this.minuteAtX(c), i.duration), i.min, i.max), l = Math.min(n, a), d = Math.max(n, a);
|
|
796
|
+
o.style.left = `${(l - i.min) * this.pxPerMinute}px`, o.style.width = `${(d - l) * this.pxPerMinute}px`;
|
|
728
797
|
};
|
|
729
|
-
w(
|
|
798
|
+
w(s, {
|
|
730
799
|
onMove: ({ event: c }) => r(c.clientX),
|
|
731
800
|
onEnd: ({ moved: c, event: a }) => {
|
|
732
801
|
if (o.remove(), !c) return;
|
|
733
|
-
const l =
|
|
734
|
-
let d = Math.min(
|
|
735
|
-
|
|
802
|
+
const l = f(x(this.minuteAtX(a.clientX), i.duration), i.min, i.max);
|
|
803
|
+
let d = Math.min(n, l), p = Math.max(n, l);
|
|
804
|
+
p <= d && (p = Math.min(d + i.duration, i.max)), !(p <= d) && this.cal.commitSelect(this.timeAt(d), this.timeAt(p), e, a);
|
|
736
805
|
}
|
|
737
806
|
});
|
|
738
807
|
});
|
|
739
808
|
}
|
|
740
|
-
fillResourceCell(t, e,
|
|
809
|
+
fillResourceCell(t, e, s) {
|
|
741
810
|
if (e.render) {
|
|
742
|
-
const
|
|
743
|
-
typeof
|
|
811
|
+
const n = e.render(s);
|
|
812
|
+
typeof n == "string" ? t.innerHTML = n : t.appendChild(n);
|
|
744
813
|
return;
|
|
745
814
|
}
|
|
746
815
|
if ((e.field === "title" || !e.field) && this.cal.options.renderResource) {
|
|
747
|
-
const
|
|
748
|
-
typeof
|
|
816
|
+
const n = this.cal.options.renderResource(s);
|
|
817
|
+
typeof n == "string" ? t.innerHTML = n : t.appendChild(n);
|
|
749
818
|
return;
|
|
750
819
|
}
|
|
751
|
-
const
|
|
752
|
-
t.textContent =
|
|
820
|
+
const i = e.field ? s.raw[e.field] : s.title;
|
|
821
|
+
t.textContent = i != null ? String(i) : "";
|
|
753
822
|
}
|
|
754
823
|
renderNowIndicator() {
|
|
755
|
-
var
|
|
756
|
-
if ((o = (
|
|
824
|
+
var n, o;
|
|
825
|
+
if ((o = (n = this.overlay) == null ? void 0 : n.querySelector(".zc-tl-now")) == null || o.remove(), !this.cal.options.nowIndicator || !this.overlay) return;
|
|
757
826
|
const t = this.cal.now();
|
|
758
827
|
if (!t.isSame(this.cal.date, "day")) return;
|
|
759
|
-
const e = this.cal.axis,
|
|
760
|
-
if (
|
|
761
|
-
const
|
|
762
|
-
|
|
828
|
+
const e = this.cal.axis, s = g(t);
|
|
829
|
+
if (s < e.min || s > e.max) return;
|
|
830
|
+
const i = h("div", "zc-tl-now");
|
|
831
|
+
i.style.left = `${(s - e.min) * this.pxPerMinute}px`, this.overlay.appendChild(i);
|
|
763
832
|
}
|
|
764
833
|
unmount() {
|
|
765
834
|
var t, e;
|
|
@@ -770,13 +839,13 @@ const M = {
|
|
|
770
839
|
code: "en",
|
|
771
840
|
buttons: { today: "Today", prev: "‹", next: "›" },
|
|
772
841
|
ariaLabels: { today: "Today", prev: "Previous", next: "Next" }
|
|
773
|
-
},
|
|
774
|
-
class
|
|
842
|
+
}, K = { start: "", center: "title", end: "today prev next" };
|
|
843
|
+
class it {
|
|
775
844
|
constructor(t, e = {}) {
|
|
776
|
-
this.viewImpl = null, this.bodyEl = null, this.titleEl = null, this.el = t, this.options = e, this.events = new
|
|
845
|
+
this.viewImpl = null, this.bodyEl = null, this.titleEl = null, this.resourceRenderScheduled = !1, this.el = t, this.options = e, this.events = new V(e.timezone), this.resources = new W(
|
|
777
846
|
e.resourceGroupField ?? "group",
|
|
778
847
|
e.resourceOrder ?? "order"
|
|
779
|
-
), this._view = e.view ?? "day", this._date = e.date ? b(e.date, e.timezone) :
|
|
848
|
+
), this._view = e.view ?? "day", this._date = e.date ? b(e.date, e.timezone) : Y(e.timezone), Array.isArray(e.resources) && this.resources.set(e.resources), Array.isArray(e.events) && this.events.set(e.events);
|
|
780
849
|
}
|
|
781
850
|
// ---- derived state -------------------------------------------------------
|
|
782
851
|
get tz() {
|
|
@@ -789,7 +858,7 @@ class Q {
|
|
|
789
858
|
return this._view;
|
|
790
859
|
}
|
|
791
860
|
get axis() {
|
|
792
|
-
return
|
|
861
|
+
return F(this.options.slot);
|
|
793
862
|
}
|
|
794
863
|
get locale() {
|
|
795
864
|
const t = this.options.locale;
|
|
@@ -817,6 +886,11 @@ class Q {
|
|
|
817
886
|
getView() {
|
|
818
887
|
return { type: this._view, activeStart: this.activeStart, activeEnd: this.activeEnd };
|
|
819
888
|
}
|
|
889
|
+
/** Default business hours (normalised to an array). */
|
|
890
|
+
get businessHours() {
|
|
891
|
+
const t = this.options.businessHours;
|
|
892
|
+
return t ? Array.isArray(t) ? t : [t] : [];
|
|
893
|
+
}
|
|
820
894
|
isDayClosed() {
|
|
821
895
|
const t = this.options.dayClosed;
|
|
822
896
|
return t === void 0 ? !1 : typeof t == "function" ? t(this._date) : t;
|
|
@@ -828,7 +902,7 @@ class Q {
|
|
|
828
902
|
return this.options.selectable === !0;
|
|
829
903
|
}
|
|
830
904
|
now() {
|
|
831
|
-
return
|
|
905
|
+
return Y(this.tz);
|
|
832
906
|
}
|
|
833
907
|
// ---- lifecycle -----------------------------------------------------------
|
|
834
908
|
render() {
|
|
@@ -844,11 +918,11 @@ class Q {
|
|
|
844
918
|
if (!e) throw new Error("[@ziix/calendar] render() must run before a view is created");
|
|
845
919
|
switch (t) {
|
|
846
920
|
case "day":
|
|
847
|
-
return new
|
|
921
|
+
return new q(this, e);
|
|
848
922
|
case "resource-day":
|
|
849
|
-
return new
|
|
923
|
+
return new G(this, e);
|
|
850
924
|
case "timeline":
|
|
851
|
-
return new
|
|
925
|
+
return new J(this, e);
|
|
852
926
|
default:
|
|
853
927
|
throw new Error(`[@ziix/calendar] unknown view: ${String(t)}`);
|
|
854
928
|
}
|
|
@@ -879,21 +953,21 @@ class Q {
|
|
|
879
953
|
typeof this.options.resources == "function" && (await this.refetchResources(), this.mountView()), await this.refetchEvents();
|
|
880
954
|
}
|
|
881
955
|
async refetchResources() {
|
|
882
|
-
var
|
|
956
|
+
var s;
|
|
883
957
|
const t = this.options.resources;
|
|
884
958
|
if (typeof t != "function") return;
|
|
885
|
-
const e = (
|
|
959
|
+
const e = (s = this.viewImpl) == null ? void 0 : s.range();
|
|
886
960
|
e && this.resources.set(await t(e));
|
|
887
961
|
}
|
|
888
962
|
async refetchEvents() {
|
|
889
|
-
var i, n,
|
|
890
|
-
const t = this.options.events, e = (
|
|
891
|
-
typeof t == "function" && e && this.events.set(await t(e)), (
|
|
963
|
+
var s, i, n, o;
|
|
964
|
+
const t = this.options.events, e = (s = this.viewImpl) == null ? void 0 : s.range();
|
|
965
|
+
typeof t == "function" && e && this.events.set(await t(e)), (n = (i = this.options).onEventsSet) == null || n.call(i, this.events.all()), (o = this.viewImpl) == null || o.renderEvents();
|
|
892
966
|
}
|
|
893
967
|
addEvent(t) {
|
|
894
|
-
var
|
|
968
|
+
var s;
|
|
895
969
|
const e = this.events.add(t);
|
|
896
|
-
return (
|
|
970
|
+
return (s = this.viewImpl) == null || s.renderEvents(), this.handle(e);
|
|
897
971
|
}
|
|
898
972
|
getEventById(t) {
|
|
899
973
|
const e = this.events.get(t);
|
|
@@ -909,17 +983,27 @@ class Q {
|
|
|
909
983
|
const e = this.resources.get(t);
|
|
910
984
|
return e ? this.resourceHandle(e) : null;
|
|
911
985
|
}
|
|
986
|
+
/**
|
|
987
|
+
* Coalesce resource-area re-renders: many setExtendedProp calls in a row (e.g.
|
|
988
|
+
* pushing work hours / punch-ins for every resource) collapse into a single
|
|
989
|
+
* cell update on the next microtask, and event bars are never rebuilt — so the
|
|
990
|
+
* timeline doesn't flicker.
|
|
991
|
+
*/
|
|
992
|
+
scheduleResourceRender() {
|
|
993
|
+
this.resourceRenderScheduled || (this.resourceRenderScheduled = !0, queueMicrotask(() => {
|
|
994
|
+
var t, e;
|
|
995
|
+
this.resourceRenderScheduled = !1, (t = this.viewImpl) != null && t.renderResources ? this.viewImpl.renderResources() : (e = this.viewImpl) == null || e.renderEvents();
|
|
996
|
+
}));
|
|
997
|
+
}
|
|
912
998
|
resourceHandle(t) {
|
|
913
999
|
return {
|
|
914
1000
|
id: t.id,
|
|
915
1001
|
resource: t,
|
|
916
|
-
setExtendedProp: (e,
|
|
917
|
-
|
|
918
|
-
t.extendedProps[e] = i, (n = this.viewImpl) == null || n.renderEvents();
|
|
1002
|
+
setExtendedProp: (e, s) => {
|
|
1003
|
+
t.extendedProps[e] = s, this.scheduleResourceRender();
|
|
919
1004
|
},
|
|
920
|
-
setProp: (e,
|
|
921
|
-
|
|
922
|
-
e === "title" ? t.title = i : t.group = i, (n = this.viewImpl) == null || n.renderEvents();
|
|
1005
|
+
setProp: (e, s) => {
|
|
1006
|
+
e === "title" ? t.title = s : t.group = s, this.scheduleResourceRender();
|
|
923
1007
|
}
|
|
924
1008
|
};
|
|
925
1009
|
}
|
|
@@ -931,45 +1015,45 @@ class Q {
|
|
|
931
1015
|
var e;
|
|
932
1016
|
this.events.remove(t.id), (e = this.viewImpl) == null || e.renderEvents();
|
|
933
1017
|
},
|
|
934
|
-
setExtendedProp: (e,
|
|
935
|
-
var
|
|
936
|
-
t.extendedProps[e] =
|
|
1018
|
+
setExtendedProp: (e, s) => {
|
|
1019
|
+
var i;
|
|
1020
|
+
t.extendedProps[e] = s, (i = this.viewImpl) == null || i.renderEvents();
|
|
937
1021
|
}
|
|
938
1022
|
};
|
|
939
1023
|
}
|
|
940
1024
|
// ---- rendering helpers used by views ------------------------------------
|
|
941
1025
|
/** Build the inner body of an event, honouring the `renderEvent` hook. */
|
|
942
1026
|
renderEventContent(t) {
|
|
943
|
-
var
|
|
1027
|
+
var i, n;
|
|
944
1028
|
const e = document.createElement("div");
|
|
945
1029
|
e.className = "zc-event-main";
|
|
946
|
-
const
|
|
947
|
-
return
|
|
1030
|
+
const s = (n = (i = this.options).renderEvent) == null ? void 0 : n.call(i, t);
|
|
1031
|
+
return s != null ? typeof s == "string" ? e.innerHTML = s : e.appendChild(s) : e.appendChild(this.defaultEventContent(t)), e;
|
|
948
1032
|
}
|
|
949
1033
|
defaultEventContent(t) {
|
|
950
1034
|
const e = document.createElement("div");
|
|
951
1035
|
e.className = "zc-event-default";
|
|
952
|
-
const i = document.createElement("span");
|
|
953
|
-
i.className = "zc-event-time";
|
|
954
|
-
const n = this.options.timeFormat ?? { hour: "2-digit", minute: "2-digit", hour12: !1 };
|
|
955
|
-
i.textContent = L(t.start, n, this.locale.intl ?? this.locale.code, this.tz);
|
|
956
1036
|
const s = document.createElement("span");
|
|
957
|
-
|
|
1037
|
+
s.className = "zc-event-time";
|
|
1038
|
+
const i = this.options.timeFormat ?? { hour: "2-digit", minute: "2-digit", hour12: !1 };
|
|
1039
|
+
s.textContent = A(t.start, i, this.locale.intl ?? this.locale.code, this.tz);
|
|
1040
|
+
const n = document.createElement("span");
|
|
1041
|
+
return n.className = "zc-event-title", n.textContent = t.title, e.append(s, n), e;
|
|
958
1042
|
}
|
|
959
1043
|
// ---- callback dispatch (called by views) --------------------------------
|
|
960
|
-
fireEventClick(t, e,
|
|
961
|
-
var
|
|
962
|
-
(
|
|
1044
|
+
fireEventClick(t, e, s) {
|
|
1045
|
+
var i, n;
|
|
1046
|
+
(n = (i = this.options).onEventClick) == null || n.call(i, { event: t, el: e, jsEvent: s });
|
|
963
1047
|
}
|
|
964
1048
|
fireEventMount(t, e) {
|
|
965
|
-
var
|
|
966
|
-
(
|
|
1049
|
+
var s, i;
|
|
1050
|
+
(i = (s = this.options).onEventMount) == null || i.call(s, { event: t, el: e });
|
|
967
1051
|
}
|
|
968
1052
|
/** Attach a right-click handler to an event bar when `onEventContextMenu` is set. */
|
|
969
1053
|
bindContextMenu(t, e) {
|
|
970
|
-
const
|
|
971
|
-
|
|
972
|
-
|
|
1054
|
+
const s = this.options.onEventContextMenu;
|
|
1055
|
+
s && t.addEventListener("contextmenu", (i) => {
|
|
1056
|
+
i.preventDefault(), s({ event: e, el: t, jsEvent: i });
|
|
973
1057
|
});
|
|
974
1058
|
}
|
|
975
1059
|
/** Whether events are allowed to overlap on the same resource (default true). */
|
|
@@ -977,9 +1061,9 @@ class Q {
|
|
|
977
1061
|
const t = this.options.eventOverlap;
|
|
978
1062
|
return t === void 0 ? !0 : typeof t == "function" ? t() : t;
|
|
979
1063
|
}
|
|
980
|
-
hasCollision(t, e,
|
|
1064
|
+
hasCollision(t, e, s, i) {
|
|
981
1065
|
return this.events.all().some(
|
|
982
|
-
(
|
|
1066
|
+
(n) => n.id !== t.id && n.resourceId === i && n.start.isBefore(s) && n.end.isAfter(e)
|
|
983
1067
|
);
|
|
984
1068
|
}
|
|
985
1069
|
/**
|
|
@@ -987,65 +1071,65 @@ class Q {
|
|
|
987
1071
|
* re-render, and fire `onEventChange`. Returns false (and reverts the live
|
|
988
1072
|
* preview by re-rendering) when the move is rejected.
|
|
989
1073
|
*/
|
|
990
|
-
commitEventChange(t, e,
|
|
991
|
-
var c, a, l, d,
|
|
992
|
-
if (t.start.isSame(e) && t.end.isSame(
|
|
1074
|
+
commitEventChange(t, e, s, i) {
|
|
1075
|
+
var c, a, l, d, p;
|
|
1076
|
+
if (t.start.isSame(e) && t.end.isSame(s) && t.resourceId === i)
|
|
993
1077
|
return (c = this.viewImpl) == null || c.renderEvents(), !1;
|
|
994
|
-
if (!this.allowsOverlap() && this.hasCollision(t, e,
|
|
1078
|
+
if (!this.allowsOverlap() && this.hasCollision(t, e, s, i))
|
|
995
1079
|
return (a = this.viewImpl) == null || a.renderEvents(), !1;
|
|
996
1080
|
const o = { ...t };
|
|
997
|
-
t.start = e, t.end =
|
|
1081
|
+
t.start = e, t.end = s, t.resourceId = i, (l = this.viewImpl) == null || l.renderEvents();
|
|
998
1082
|
const r = () => {
|
|
999
|
-
var
|
|
1000
|
-
t.start = o.start, t.end = o.end, t.resourceId = o.resourceId, (
|
|
1083
|
+
var m;
|
|
1084
|
+
t.start = o.start, t.end = o.end, t.resourceId = o.resourceId, (m = this.viewImpl) == null || m.renderEvents();
|
|
1001
1085
|
};
|
|
1002
|
-
return (
|
|
1086
|
+
return (p = (d = this.options).onEventChange) == null || p.call(d, { event: t, oldEvent: o, revert: r }), !0;
|
|
1003
1087
|
}
|
|
1004
1088
|
/** Gate a drag-selection on `selectAllow`, then fire `onSelect`. */
|
|
1005
|
-
commitSelect(t, e,
|
|
1006
|
-
var
|
|
1007
|
-
return this.options.selectAllow && !this.options.selectAllow({ start: t, end: e, resource:
|
|
1089
|
+
commitSelect(t, e, s, i) {
|
|
1090
|
+
var n, o;
|
|
1091
|
+
return this.options.selectAllow && !this.options.selectAllow({ start: t, end: e, resource: s }) ? !1 : ((o = (n = this.options).onSelect) == null || o.call(n, { start: t, end: e, resource: s, jsEvent: i }), !0);
|
|
1008
1092
|
}
|
|
1009
1093
|
// ---- toolbar -------------------------------------------------------------
|
|
1010
1094
|
renderToolbar() {
|
|
1011
1095
|
if (this.options.toolbar === !1) return;
|
|
1012
|
-
const t = this.options.toolbar ??
|
|
1096
|
+
const t = this.options.toolbar ?? K, e = document.createElement("div");
|
|
1013
1097
|
e.className = "zc-toolbar";
|
|
1014
|
-
for (const
|
|
1015
|
-
const
|
|
1016
|
-
|
|
1017
|
-
const
|
|
1018
|
-
if (
|
|
1019
|
-
for (const o of
|
|
1098
|
+
for (const s of ["start", "center", "end"]) {
|
|
1099
|
+
const i = document.createElement("div");
|
|
1100
|
+
i.className = `zc-toolbar-section zc-toolbar-${s}`;
|
|
1101
|
+
const n = t[s];
|
|
1102
|
+
if (n)
|
|
1103
|
+
for (const o of n.split(/\s+/).filter(Boolean)) {
|
|
1020
1104
|
const r = o.split(",").filter(Boolean);
|
|
1021
1105
|
if (r.length === 1 && r[0] === "title") {
|
|
1022
|
-
|
|
1106
|
+
i.appendChild(this.renderToolbarToken("title"));
|
|
1023
1107
|
continue;
|
|
1024
1108
|
}
|
|
1025
1109
|
const c = document.createElement("div");
|
|
1026
1110
|
c.className = "zc-btn-group";
|
|
1027
1111
|
for (const a of r) c.appendChild(this.renderToolbarToken(a));
|
|
1028
|
-
|
|
1112
|
+
i.appendChild(c);
|
|
1029
1113
|
}
|
|
1030
|
-
e.appendChild(
|
|
1114
|
+
e.appendChild(i);
|
|
1031
1115
|
}
|
|
1032
1116
|
this.el.appendChild(e);
|
|
1033
1117
|
}
|
|
1034
1118
|
renderToolbarToken(t) {
|
|
1035
|
-
var
|
|
1119
|
+
var n;
|
|
1036
1120
|
if (t === "title")
|
|
1037
1121
|
return this.titleEl = document.createElement("h2"), this.titleEl.className = "zc-title", this.titleEl;
|
|
1038
1122
|
const e = document.createElement("button");
|
|
1039
1123
|
e.type = "button", e.className = "zc-btn", e.dataset.zcButton = t;
|
|
1040
|
-
const
|
|
1124
|
+
const s = this.locale.buttons ?? {}, i = this.locale.ariaLabels ?? {};
|
|
1041
1125
|
if (t === "today")
|
|
1042
|
-
e.textContent =
|
|
1126
|
+
e.textContent = s.today ?? "Today", i.today && e.setAttribute("aria-label", i.today), e.onclick = () => this.today();
|
|
1043
1127
|
else if (t === "prev")
|
|
1044
|
-
e.textContent =
|
|
1128
|
+
e.textContent = s.prev ?? "‹", e.setAttribute("aria-label", i.prev ?? "Previous"), e.onclick = () => this.prev();
|
|
1045
1129
|
else if (t === "next")
|
|
1046
|
-
e.textContent =
|
|
1130
|
+
e.textContent = s.next ?? "›", e.setAttribute("aria-label", i.next ?? "Next"), e.onclick = () => this.next();
|
|
1047
1131
|
else {
|
|
1048
|
-
const o = (
|
|
1132
|
+
const o = (n = this.options.buttons) == null ? void 0 : n[t];
|
|
1049
1133
|
if (o) {
|
|
1050
1134
|
if (o.icon) {
|
|
1051
1135
|
const r = document.createElement("span");
|
|
@@ -1062,22 +1146,22 @@ class Q {
|
|
|
1062
1146
|
this.titleEl && (this.titleEl.textContent = ((t = this.viewImpl) == null ? void 0 : t.title()) ?? "");
|
|
1063
1147
|
}
|
|
1064
1148
|
emitDatesSet() {
|
|
1065
|
-
var e,
|
|
1149
|
+
var e, s, i;
|
|
1066
1150
|
const t = (e = this.viewImpl) == null ? void 0 : e.range();
|
|
1067
|
-
t && ((
|
|
1151
|
+
t && ((i = (s = this.options).onDatesSet) == null || i.call(s, { start: t.start, end: t.end, view: this._view }));
|
|
1068
1152
|
}
|
|
1069
1153
|
}
|
|
1070
1154
|
export {
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1155
|
+
it as Calendar,
|
|
1156
|
+
V as EventStore,
|
|
1157
|
+
W as ResourceStore,
|
|
1158
|
+
F as buildAxis,
|
|
1159
|
+
g as dayMinutes,
|
|
1160
|
+
A as intlFormat,
|
|
1161
|
+
I as minutesToTime,
|
|
1162
|
+
Y as nowTz,
|
|
1163
|
+
$ as packEvents,
|
|
1164
|
+
L as timeToMinutes,
|
|
1081
1165
|
b as toTz
|
|
1082
1166
|
};
|
|
1083
1167
|
//# sourceMappingURL=ziix-calendar.js.map
|