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