@ziix/calendar 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -36
- package/dist/index.d.ts +12 -4
- package/dist/ziix-calendar.css +1 -1
- package/dist/ziix-calendar.js +157 -120
- package/dist/ziix-calendar.js.map +1 -1
- package/package.json +4 -3
package/dist/ziix-calendar.js
CHANGED
|
@@ -7,10 +7,10 @@ function b(p, t) {
|
|
|
7
7
|
const e = C(p);
|
|
8
8
|
return t ? e.tz(t) : e;
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function P(p) {
|
|
11
11
|
return p ? C().tz(p) : C();
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function $(p) {
|
|
14
14
|
const t = p.split(":"), e = Number(t[0]) || 0, i = Number(t[1]) || 0;
|
|
15
15
|
return e * 60 + i;
|
|
16
16
|
}
|
|
@@ -25,7 +25,7 @@ function L(p, t, e, i) {
|
|
|
25
25
|
return new Intl.DateTimeFormat(e, { ...t, timeZone: i }).format(p.toDate());
|
|
26
26
|
}
|
|
27
27
|
function N(p = {}) {
|
|
28
|
-
const t =
|
|
28
|
+
const t = $(p.min ?? "00:00"), e = $(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
29
|
return { min: t, max: e, duration: i, labelInterval: n, slots: o, totalMinutes: s };
|
|
30
30
|
}
|
|
31
31
|
class _ {
|
|
@@ -81,13 +81,15 @@ class X {
|
|
|
81
81
|
this.groupField = t, this.orderField = e, this.list = [];
|
|
82
82
|
}
|
|
83
83
|
normalize(t) {
|
|
84
|
-
const e = t[this.groupField], i = t[this.orderField];
|
|
84
|
+
const e = t[this.groupField], i = t[this.orderField], n = /* @__PURE__ */ new Set(["id", "title", "group", "order", "extendedProps", this.groupField, this.orderField]), s = {};
|
|
85
|
+
for (const o of Object.keys(t))
|
|
86
|
+
n.has(o) || (s[o] = t[o]);
|
|
85
87
|
return {
|
|
86
88
|
id: String(t.id),
|
|
87
89
|
title: t.title ?? "",
|
|
88
90
|
group: e != null ? String(e) : null,
|
|
89
91
|
order: typeof i == "number" ? i : 0,
|
|
90
|
-
extendedProps: t.extendedProps ?? {},
|
|
92
|
+
extendedProps: { ...s, ...t.extendedProps ?? {} },
|
|
91
93
|
raw: t
|
|
92
94
|
};
|
|
93
95
|
}
|
|
@@ -104,7 +106,7 @@ class X {
|
|
|
104
106
|
* Resources in display order. With `resourceOrder: 'id'` they are sorted by a
|
|
105
107
|
* natural id comparison (so 'E2' precedes 'E10'); with a numeric order field
|
|
106
108
|
* they sort by it; otherwise the original input order is preserved (sort is
|
|
107
|
-
* stable)
|
|
109
|
+
* stable).
|
|
108
110
|
*/
|
|
109
111
|
ordered() {
|
|
110
112
|
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);
|
|
@@ -122,7 +124,7 @@ class X {
|
|
|
122
124
|
return t;
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
|
-
function
|
|
127
|
+
function S(p) {
|
|
126
128
|
const t = [...p].sort(
|
|
127
129
|
(o, r) => o.start.valueOf() - r.start.valueOf() || r.end.valueOf() - o.end.valueOf()
|
|
128
130
|
), e = [];
|
|
@@ -130,19 +132,19 @@ function I(p) {
|
|
|
130
132
|
const s = () => {
|
|
131
133
|
if (i.length === 0) return;
|
|
132
134
|
const o = [];
|
|
133
|
-
for (const
|
|
134
|
-
let
|
|
135
|
+
for (const a of i) {
|
|
136
|
+
let c = !1;
|
|
135
137
|
for (const l of o)
|
|
136
|
-
if (l[l.length - 1].end.valueOf() <=
|
|
137
|
-
l.push(
|
|
138
|
+
if (l[l.length - 1].end.valueOf() <= a.start.valueOf()) {
|
|
139
|
+
l.push(a), c = !0;
|
|
138
140
|
break;
|
|
139
141
|
}
|
|
140
|
-
|
|
142
|
+
c || o.push([a]);
|
|
141
143
|
}
|
|
142
144
|
const r = o.length;
|
|
143
|
-
o.forEach((
|
|
144
|
-
for (const l of
|
|
145
|
-
e.push({ event: l, col:
|
|
145
|
+
o.forEach((a, c) => {
|
|
146
|
+
for (const l of a)
|
|
147
|
+
e.push({ event: l, col: c, cols: r, left: c / r, width: 1 / r });
|
|
146
148
|
}), i = [], n = -1 / 0;
|
|
147
149
|
};
|
|
148
150
|
for (const o of t)
|
|
@@ -152,19 +154,19 @@ function I(p) {
|
|
|
152
154
|
function w(p, t) {
|
|
153
155
|
const e = t.threshold ?? 4, i = p.clientX, n = p.clientY;
|
|
154
156
|
let s = !1;
|
|
155
|
-
const o = (
|
|
157
|
+
const o = (a) => {
|
|
156
158
|
var u, g;
|
|
157
|
-
const
|
|
158
|
-
!s && Math.hypot(l, d) < e || (s || (s = !0, (u = t.onStart) == null || u.call(t,
|
|
159
|
-
}, r = (
|
|
159
|
+
const c = a, l = c.clientX - i, d = c.clientY - n;
|
|
160
|
+
!s && Math.hypot(l, d) < e || (s || (s = !0, (u = t.onStart) == null || u.call(t, c)), (g = t.onMove) == null || g.call(t, { dx: l, dy: d, moved: !0, event: c }));
|
|
161
|
+
}, r = (a) => {
|
|
160
162
|
var l;
|
|
161
163
|
window.removeEventListener("pointermove", o), window.removeEventListener("pointerup", r), window.removeEventListener("pointercancel", r);
|
|
162
|
-
const
|
|
164
|
+
const c = a;
|
|
163
165
|
(l = t.onEnd) == null || l.call(t, {
|
|
164
|
-
dx:
|
|
165
|
-
dy:
|
|
166
|
+
dx: c.clientX - i,
|
|
167
|
+
dy: c.clientY - n,
|
|
166
168
|
moved: s,
|
|
167
|
-
event:
|
|
169
|
+
event: c
|
|
168
170
|
});
|
|
169
171
|
};
|
|
170
172
|
window.addEventListener("pointermove", o), window.addEventListener("pointerup", r), window.addEventListener("pointercancel", r);
|
|
@@ -229,14 +231,14 @@ class F {
|
|
|
229
231
|
renderEvents() {
|
|
230
232
|
if (!this.content) return;
|
|
231
233
|
this.content.querySelectorAll(".zc-event").forEach((i) => i.remove());
|
|
232
|
-
const t = this.cal.axis, e =
|
|
234
|
+
const t = this.cal.axis, e = S(this.eventsFor());
|
|
233
235
|
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),
|
|
235
|
-
d.dataset.eventId = n.id, d.style.top = `${
|
|
236
|
+
const n = i.event, s = f(n.start), o = f(n.end) || t.max, r = m(s, t.min, t.max), a = m(o, t.min, t.max), c = (r - t.min) * this.pxPerMinute, l = Math.max(E - 2, (a - r) * this.pxPerMinute), d = h("div", "zc-event");
|
|
237
|
+
d.dataset.eventId = n.id, d.style.top = `${c}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
238
|
}
|
|
237
239
|
this.renderNowIndicator();
|
|
238
240
|
}
|
|
239
|
-
// ---- interaction
|
|
241
|
+
// ---- interaction ---------------------------------------------------------
|
|
240
242
|
timeAt(t) {
|
|
241
243
|
return this.cal.date.startOf("day").add(t, "minute");
|
|
242
244
|
}
|
|
@@ -255,22 +257,22 @@ class F {
|
|
|
255
257
|
t.appendChild(i), i.addEventListener("pointerdown", (n) => this.beginResize(n, t, e)), t.addEventListener("pointerdown", (n) => {
|
|
256
258
|
if (n.button !== 0 || n.target.closest(".zc-resize-handle")) return;
|
|
257
259
|
n.preventDefault();
|
|
258
|
-
const s = this.cal.axis, o = e.end.diff(e.start, "minute"), r = f(e.start),
|
|
259
|
-
x(r + (this.minuteAtY(l) -
|
|
260
|
+
const s = this.cal.axis, o = e.end.diff(e.start, "minute"), r = f(e.start), a = this.minuteAtY(n.clientY), c = (l) => m(
|
|
261
|
+
x(r + (this.minuteAtY(l) - a), s.duration),
|
|
260
262
|
s.min,
|
|
261
263
|
s.max - o
|
|
262
264
|
);
|
|
263
265
|
w(n, {
|
|
264
266
|
onStart: () => t.classList.add("zc-dragging"),
|
|
265
267
|
onMove: ({ event: l }) => {
|
|
266
|
-
t.style.top = `${(
|
|
268
|
+
t.style.top = `${(c(l.clientY) - s.min) * this.pxPerMinute}px`;
|
|
267
269
|
},
|
|
268
270
|
onEnd: ({ moved: l, event: d }) => {
|
|
269
271
|
if (t.classList.remove("zc-dragging"), !l) {
|
|
270
272
|
this.cal.fireEventClick(e, t, d);
|
|
271
273
|
return;
|
|
272
274
|
}
|
|
273
|
-
const u = this.timeAt(
|
|
275
|
+
const u = this.timeAt(c(d.clientY));
|
|
274
276
|
this.cal.commitEventChange(e, u, u.add(o, "minute"), e.resourceId);
|
|
275
277
|
}
|
|
276
278
|
});
|
|
@@ -285,8 +287,8 @@ class F {
|
|
|
285
287
|
onMove: ({ event: r }) => {
|
|
286
288
|
e.style.height = `${(o(r.clientY) - s) * this.pxPerMinute}px`;
|
|
287
289
|
},
|
|
288
|
-
onEnd: ({ moved: r, event:
|
|
289
|
-
e.classList.remove("zc-dragging"), r && this.cal.commitEventChange(i, i.start, this.timeAt(o(
|
|
290
|
+
onEnd: ({ moved: r, event: a }) => {
|
|
291
|
+
e.classList.remove("zc-dragging"), r && this.cal.commitEventChange(i, i.start, this.timeAt(o(a.clientY)), i.resourceId);
|
|
290
292
|
}
|
|
291
293
|
});
|
|
292
294
|
}
|
|
@@ -297,16 +299,16 @@ class F {
|
|
|
297
299
|
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
300
|
this.content.appendChild(n);
|
|
299
301
|
const s = (o) => {
|
|
300
|
-
const r = m(x(this.minuteAtY(o), e.duration), e.min, e.max),
|
|
301
|
-
n.style.top = `${(
|
|
302
|
+
const r = m(x(this.minuteAtY(o), e.duration), e.min, e.max), a = Math.min(i, r), c = Math.max(i, r);
|
|
303
|
+
n.style.top = `${(a - e.min) * this.pxPerMinute}px`, n.style.height = `${(c - a) * this.pxPerMinute}px`;
|
|
302
304
|
};
|
|
303
305
|
w(t, {
|
|
304
306
|
onMove: ({ event: o }) => s(o.clientY),
|
|
305
307
|
onEnd: ({ moved: o, event: r }) => {
|
|
306
308
|
if (n.remove(), !o) return;
|
|
307
|
-
const
|
|
308
|
-
let
|
|
309
|
-
l <=
|
|
309
|
+
const a = m(x(this.minuteAtY(r.clientY), e.duration), e.min, e.max);
|
|
310
|
+
let c = Math.min(i, a), l = Math.max(i, a);
|
|
311
|
+
l <= c && (l = Math.min(c + e.duration, e.max)), !(l <= c) && this.cal.commitSelect(this.timeAt(c), this.timeAt(l), null, r);
|
|
310
312
|
}
|
|
311
313
|
});
|
|
312
314
|
});
|
|
@@ -363,24 +365,24 @@ class V {
|
|
|
363
365
|
n.appendChild(this.colsEl), this.rootEl.appendChild(n), this.root.appendChild(this.rootEl), this.renderEvents();
|
|
364
366
|
}
|
|
365
367
|
buildHead(t, e) {
|
|
366
|
-
var r,
|
|
368
|
+
var r, a;
|
|
367
369
|
const i = h("div", "zc-rg-head"), n = h("div", "zc-rg-corner");
|
|
368
370
|
i.appendChild(n);
|
|
369
371
|
const s = h("div", "zc-rg-head-cols");
|
|
370
372
|
if (e) {
|
|
371
|
-
const
|
|
373
|
+
const c = h("div", "zc-rg-group-row");
|
|
372
374
|
for (const l of t) {
|
|
373
375
|
const d = h("div", "zc-rg-group-band");
|
|
374
|
-
d.style.flex = `${l.resources.length} 1 0`, d.textContent = l.group ?? "",
|
|
376
|
+
d.style.flex = `${l.resources.length} 1 0`, d.textContent = l.group ?? "", c.appendChild(d);
|
|
375
377
|
}
|
|
376
|
-
s.appendChild(
|
|
378
|
+
s.appendChild(c);
|
|
377
379
|
}
|
|
378
380
|
const o = h("div", "zc-rg-label-row");
|
|
379
|
-
for (const
|
|
381
|
+
for (const c of t.flatMap((l) => l.resources)) {
|
|
380
382
|
const l = h("div", "zc-rg-label");
|
|
381
|
-
l.dataset.resourceId =
|
|
382
|
-
const d = (
|
|
383
|
-
d != null ? typeof d == "string" ? l.innerHTML = d : l.appendChild(d) : l.textContent =
|
|
383
|
+
l.dataset.resourceId = c.id;
|
|
384
|
+
const d = (a = (r = this.cal.options).renderResource) == null ? void 0 : a.call(r, c);
|
|
385
|
+
d != null ? typeof d == "string" ? l.innerHTML = d : l.appendChild(d) : l.textContent = c.title, o.appendChild(l);
|
|
384
386
|
}
|
|
385
387
|
return s.appendChild(o), i.appendChild(s), i;
|
|
386
388
|
}
|
|
@@ -407,9 +409,9 @@ class V {
|
|
|
407
409
|
const t = this.range(), e = this.cal.axis;
|
|
408
410
|
for (const { resource: i, content: n } of this.cols) {
|
|
409
411
|
n.querySelectorAll(".zc-event").forEach((o) => o.remove());
|
|
410
|
-
const s =
|
|
412
|
+
const s = S(this.cal.events.inRange(t.start, t.end, i.id));
|
|
411
413
|
for (const o of s) {
|
|
412
|
-
const r = o.event,
|
|
414
|
+
const r = o.event, a = f(r.start), c = f(r.end) || e.max, l = m(a, e.min, e.max), d = m(c, 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
415
|
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
416
|
}
|
|
415
417
|
}
|
|
@@ -440,6 +442,18 @@ class V {
|
|
|
440
442
|
const s = n == null ? void 0 : n.closest(".zc-rg-col[data-resource-id]");
|
|
441
443
|
return s ? s.dataset.resourceId ?? null : void 0;
|
|
442
444
|
}
|
|
445
|
+
highlightCol(t, e) {
|
|
446
|
+
var s;
|
|
447
|
+
this.clearHighlight();
|
|
448
|
+
const i = e.style.pointerEvents;
|
|
449
|
+
e.style.pointerEvents = "none";
|
|
450
|
+
const n = document.elementFromPoint(t.clientX, t.clientY);
|
|
451
|
+
e.style.pointerEvents = i, (s = n == null ? void 0 : n.closest(".zc-rg-col[data-resource-id]")) == null || s.classList.add("zc-drop-target");
|
|
452
|
+
}
|
|
453
|
+
clearHighlight() {
|
|
454
|
+
var t;
|
|
455
|
+
(t = this.colsEl) == null || t.querySelectorAll(".zc-drop-target").forEach((e) => e.classList.remove("zc-drop-target"));
|
|
456
|
+
}
|
|
443
457
|
bindBar(t, e) {
|
|
444
458
|
if (this.cal.bindContextMenu(t, e), !this.cal.editable) {
|
|
445
459
|
t.addEventListener("click", (n) => this.cal.fireEventClick(e, t, n));
|
|
@@ -450,22 +464,22 @@ class V {
|
|
|
450
464
|
t.appendChild(i), i.addEventListener("pointerdown", (n) => this.beginResize(n, t, e)), t.addEventListener("pointerdown", (n) => {
|
|
451
465
|
if (n.button !== 0 || n.target.closest(".zc-resize-handle")) return;
|
|
452
466
|
n.preventDefault();
|
|
453
|
-
const s = this.cal.axis, o = e.end.diff(e.start, "minute"), r = f(e.start),
|
|
454
|
-
x(r + (this.minuteAtY(l) -
|
|
467
|
+
const s = this.cal.axis, o = e.end.diff(e.start, "minute"), r = f(e.start), a = this.minuteAtY(n.clientY), c = (l) => m(
|
|
468
|
+
x(r + (this.minuteAtY(l) - a), s.duration),
|
|
455
469
|
s.min,
|
|
456
470
|
s.max - o
|
|
457
471
|
);
|
|
458
472
|
w(n, {
|
|
459
473
|
onStart: () => t.classList.add("zc-dragging"),
|
|
460
474
|
onMove: ({ event: l }) => {
|
|
461
|
-
t.style.top = `${(
|
|
475
|
+
t.style.top = `${(c(l.clientY) - s.min) * this.pxPerMinute}px`, this.highlightCol(l, t);
|
|
462
476
|
},
|
|
463
477
|
onEnd: ({ moved: l, event: d }) => {
|
|
464
|
-
if (t.classList.remove("zc-dragging"), !l) {
|
|
478
|
+
if (t.classList.remove("zc-dragging"), this.clearHighlight(), !l) {
|
|
465
479
|
this.cal.fireEventClick(e, t, d);
|
|
466
480
|
return;
|
|
467
481
|
}
|
|
468
|
-
const u = this.timeAt(
|
|
482
|
+
const u = this.timeAt(c(d.clientY)), g = this.resourceIdAt(d, t) ?? e.resourceId;
|
|
469
483
|
this.cal.commitEventChange(e, u, u.add(o, "minute"), g);
|
|
470
484
|
}
|
|
471
485
|
});
|
|
@@ -480,8 +494,8 @@ class V {
|
|
|
480
494
|
onMove: ({ event: r }) => {
|
|
481
495
|
e.style.height = `${(o(r.clientY) - s) * this.pxPerMinute}px`;
|
|
482
496
|
},
|
|
483
|
-
onEnd: ({ moved: r, event:
|
|
484
|
-
e.classList.remove("zc-dragging"), r && this.cal.commitEventChange(i, i.start, this.timeAt(o(
|
|
497
|
+
onEnd: ({ moved: r, event: a }) => {
|
|
498
|
+
e.classList.remove("zc-dragging"), r && this.cal.commitEventChange(i, i.start, this.timeAt(o(a.clientY)), i.resourceId);
|
|
485
499
|
}
|
|
486
500
|
});
|
|
487
501
|
}
|
|
@@ -491,17 +505,17 @@ class V {
|
|
|
491
505
|
i.preventDefault();
|
|
492
506
|
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
507
|
t.appendChild(o);
|
|
494
|
-
const r = (
|
|
495
|
-
const
|
|
508
|
+
const r = (a) => {
|
|
509
|
+
const c = m(x(this.minuteAtY(a), n.duration), n.min, n.max), l = Math.min(s, c), d = Math.max(s, c);
|
|
496
510
|
o.style.top = `${(l - n.min) * this.pxPerMinute}px`, o.style.height = `${(d - l) * this.pxPerMinute}px`;
|
|
497
511
|
};
|
|
498
512
|
w(i, {
|
|
499
|
-
onMove: ({ event:
|
|
500
|
-
onEnd: ({ moved:
|
|
501
|
-
if (o.remove(), !
|
|
502
|
-
const l = m(x(this.minuteAtY(
|
|
513
|
+
onMove: ({ event: a }) => r(a.clientY),
|
|
514
|
+
onEnd: ({ moved: a, event: c }) => {
|
|
515
|
+
if (o.remove(), !a) return;
|
|
516
|
+
const l = m(x(this.minuteAtY(c.clientY), n.duration), n.min, n.max);
|
|
503
517
|
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,
|
|
518
|
+
u <= d && (u = Math.min(d + n.duration, n.max)), !(u <= d) && this.cal.commitSelect(this.timeAt(d), this.timeAt(u), e, c);
|
|
505
519
|
}
|
|
506
520
|
});
|
|
507
521
|
});
|
|
@@ -511,14 +525,14 @@ class V {
|
|
|
511
525
|
(t = this.rootEl) == null || t.remove(), this.rootEl = void 0, this.colsEl = void 0, this.nowLine = null, this.cols = [];
|
|
512
526
|
}
|
|
513
527
|
}
|
|
514
|
-
const
|
|
515
|
-
class
|
|
528
|
+
const H = 38, T = 26, q = 48, Y = 4, G = 90, W = 14;
|
|
529
|
+
class U {
|
|
516
530
|
constructor(t, e) {
|
|
517
531
|
this.cal = t, this.root = e;
|
|
518
532
|
}
|
|
519
533
|
// ---- geometry ------------------------------------------------------------
|
|
520
534
|
get pxPerMinute() {
|
|
521
|
-
return
|
|
535
|
+
return G / 60;
|
|
522
536
|
}
|
|
523
537
|
get width() {
|
|
524
538
|
return this.cal.axis.totalMinutes * this.pxPerMinute;
|
|
@@ -557,14 +571,14 @@ class q {
|
|
|
557
571
|
const t = h("div", "zc-tl-resource-area");
|
|
558
572
|
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
573
|
const e = h("div", "zc-tl-resource-head");
|
|
560
|
-
e.style.height = `${
|
|
574
|
+
e.style.height = `${H}px`;
|
|
561
575
|
for (const r of this.columns()) {
|
|
562
|
-
const
|
|
563
|
-
this.applyWidth(
|
|
576
|
+
const a = h("div", "zc-tl-col-head");
|
|
577
|
+
this.applyWidth(a, r.width), a.textContent = r.header ?? "", e.appendChild(a);
|
|
564
578
|
}
|
|
565
579
|
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
580
|
const i = h("div", "zc-tl-time-area");
|
|
567
|
-
this.timeHead = h("div", "zc-tl-time-head"), this.timeHead.style.height = `${
|
|
581
|
+
this.timeHead = h("div", "zc-tl-time-head"), this.timeHead.style.height = `${H}px`, this.buildAxisHeader(this.timeHead), this.timeBody = h("div", "zc-tl-time-body");
|
|
568
582
|
const n = h("div", "zc-tl-time-canvas");
|
|
569
583
|
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
584
|
this.resourceBody && this.timeBody && (this.resourceBody.scrollTop = this.timeBody.scrollTop), this.timeHead && this.timeBody && (this.timeHead.scrollLeft = this.timeBody.scrollLeft);
|
|
@@ -591,6 +605,19 @@ class q {
|
|
|
591
605
|
renderEvents() {
|
|
592
606
|
this.relayout();
|
|
593
607
|
}
|
|
608
|
+
/** Re-render only the resource-area cells, leaving event bars untouched. */
|
|
609
|
+
renderResources() {
|
|
610
|
+
this.resourceRows && this.resourceRows.querySelectorAll(".zc-tl-resource-row[data-resource-id]").forEach((t) => {
|
|
611
|
+
const e = this.cal.resources.get(t.dataset.resourceId ?? "");
|
|
612
|
+
if (e) {
|
|
613
|
+
t.innerHTML = "";
|
|
614
|
+
for (const i of this.columns()) {
|
|
615
|
+
const n = h("div", "zc-tl-col-cell");
|
|
616
|
+
this.applyWidth(n, i.width), this.fillResourceCell(n, i, e), t.appendChild(n);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
}
|
|
594
621
|
/** Rebuild rows in both panes from the current resources + events. */
|
|
595
622
|
relayout() {
|
|
596
623
|
if (!this.resourceRows || !this.rowsEl) return;
|
|
@@ -607,33 +634,33 @@ class q {
|
|
|
607
634
|
}
|
|
608
635
|
appendGroupRow(t) {
|
|
609
636
|
const e = h("div", "zc-tl-resource-row zc-tl-group-row");
|
|
610
|
-
e.style.height = `${
|
|
637
|
+
e.style.height = `${T}px`, e.textContent = t, this.resourceRows.appendChild(e);
|
|
611
638
|
const i = h("div", "zc-tl-row zc-tl-group-spacer");
|
|
612
|
-
i.style.height = `${
|
|
639
|
+
i.style.height = `${T}px`, this.rowsEl.appendChild(i);
|
|
613
640
|
}
|
|
614
641
|
appendResourceRow(t, e) {
|
|
615
|
-
const i =
|
|
616
|
-
|
|
642
|
+
const i = S(e), n = i.reduce((d, u) => Math.max(d, u.cols), 1), s = this.cal.options.eventMinHeight ?? q, o = n * s + 2 * Y, r = s, a = h("div", "zc-tl-resource-row");
|
|
643
|
+
a.style.height = `${o}px`, a.dataset.resourceId = t.id;
|
|
617
644
|
for (const d of this.columns()) {
|
|
618
645
|
const u = h("div", "zc-tl-col-cell");
|
|
619
|
-
this.applyWidth(u, d.width), this.fillResourceCell(u, d, t),
|
|
646
|
+
this.applyWidth(u, d.width), this.fillResourceCell(u, d, t), a.appendChild(u);
|
|
620
647
|
}
|
|
621
|
-
this.resourceRows.appendChild(
|
|
622
|
-
const
|
|
623
|
-
|
|
648
|
+
this.resourceRows.appendChild(a);
|
|
649
|
+
const c = h("div", "zc-tl-row");
|
|
650
|
+
c.style.height = `${o}px`, c.dataset.resourceId = t.id;
|
|
624
651
|
const l = this.cal.axis;
|
|
625
652
|
for (const d of i) {
|
|
626
653
|
const u = d.event, g = f(u.start);
|
|
627
654
|
let v = f(u.end);
|
|
628
655
|
v <= g && (v = l.max);
|
|
629
|
-
const z = m(g, l.min, l.max),
|
|
630
|
-
if (
|
|
631
|
-
const
|
|
632
|
-
y.dataset.eventId = u.id, y.style.left = `${
|
|
656
|
+
const z = m(g, l.min, l.max), I = m(v, l.min, l.max);
|
|
657
|
+
if (I <= l.min || z >= l.max) continue;
|
|
658
|
+
const R = (z - l.min) * this.pxPerMinute, B = Math.max(W, (I - z) * this.pxPerMinute), D = Y + d.col * r, y = h("div", "zc-event zc-tl-event");
|
|
659
|
+
y.dataset.eventId = u.id, y.style.left = `${R}px`, y.style.width = `${Math.min(B, this.width - R)}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), c.appendChild(y), this.cal.fireEventMount(u, y);
|
|
633
660
|
}
|
|
634
|
-
this.bindRowSelect(
|
|
661
|
+
this.bindRowSelect(c, t), this.rowsEl.appendChild(c);
|
|
635
662
|
}
|
|
636
|
-
// ---- interaction
|
|
663
|
+
// ---- interaction ---------------------------------------------------------
|
|
637
664
|
timeAt(t) {
|
|
638
665
|
return this.cal.date.startOf("day").add(t, "minute");
|
|
639
666
|
}
|
|
@@ -666,8 +693,8 @@ class q {
|
|
|
666
693
|
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
694
|
if (s.button !== 0 || s.target.closest(".zc-resize-handle")) return;
|
|
668
695
|
s.preventDefault();
|
|
669
|
-
const o = this.cal.axis, r = e.end.diff(e.start, "minute"),
|
|
670
|
-
x(
|
|
696
|
+
const o = this.cal.axis, r = e.end.diff(e.start, "minute"), a = f(e.start), c = this.minuteAtX(s.clientX), l = (d) => m(
|
|
697
|
+
x(a + (this.minuteAtX(d) - c), o.duration),
|
|
671
698
|
o.min,
|
|
672
699
|
o.max - r
|
|
673
700
|
);
|
|
@@ -694,23 +721,23 @@ class q {
|
|
|
694
721
|
w(t, {
|
|
695
722
|
onStart: () => e.classList.add("zc-dragging"),
|
|
696
723
|
onMove: ({ event: r }) => {
|
|
697
|
-
const
|
|
724
|
+
const a = o(r.clientX);
|
|
698
725
|
if (n === "end") {
|
|
699
|
-
const
|
|
700
|
-
e.style.width = `${(
|
|
726
|
+
const c = Math.max(a, f(i.start) + s.duration);
|
|
727
|
+
e.style.width = `${(c - f(i.start)) * this.pxPerMinute}px`;
|
|
701
728
|
} else {
|
|
702
|
-
const
|
|
703
|
-
e.style.left = `${(
|
|
729
|
+
const c = Math.min(a, f(i.end) - s.duration);
|
|
730
|
+
e.style.left = `${(c - s.min) * this.pxPerMinute}px`, e.style.width = `${(f(i.end) - c) * this.pxPerMinute}px`;
|
|
704
731
|
}
|
|
705
732
|
},
|
|
706
|
-
onEnd: ({ moved: r, event:
|
|
733
|
+
onEnd: ({ moved: r, event: a }) => {
|
|
707
734
|
if (e.classList.remove("zc-dragging"), !r) return;
|
|
708
|
-
const
|
|
735
|
+
const c = o(a.clientX);
|
|
709
736
|
if (n === "end") {
|
|
710
|
-
const l = Math.max(
|
|
737
|
+
const l = Math.max(c, f(i.start) + s.duration);
|
|
711
738
|
this.cal.commitEventChange(i, i.start, this.timeAt(l), i.resourceId);
|
|
712
739
|
} else {
|
|
713
|
-
const l = Math.min(
|
|
740
|
+
const l = Math.min(c, f(i.end) - s.duration);
|
|
714
741
|
this.cal.commitEventChange(i, this.timeAt(l), i.end, i.resourceId);
|
|
715
742
|
}
|
|
716
743
|
}
|
|
@@ -722,17 +749,17 @@ class q {
|
|
|
722
749
|
i.preventDefault();
|
|
723
750
|
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
751
|
t.appendChild(o);
|
|
725
|
-
const r = (
|
|
726
|
-
const
|
|
752
|
+
const r = (a) => {
|
|
753
|
+
const c = m(x(this.minuteAtX(a), n.duration), n.min, n.max), l = Math.min(s, c), d = Math.max(s, c);
|
|
727
754
|
o.style.left = `${(l - n.min) * this.pxPerMinute}px`, o.style.width = `${(d - l) * this.pxPerMinute}px`;
|
|
728
755
|
};
|
|
729
756
|
w(i, {
|
|
730
|
-
onMove: ({ event:
|
|
731
|
-
onEnd: ({ moved:
|
|
732
|
-
if (o.remove(), !
|
|
733
|
-
const l = m(x(this.minuteAtX(
|
|
757
|
+
onMove: ({ event: a }) => r(a.clientX),
|
|
758
|
+
onEnd: ({ moved: a, event: c }) => {
|
|
759
|
+
if (o.remove(), !a) return;
|
|
760
|
+
const l = m(x(this.minuteAtX(c.clientX), n.duration), n.min, n.max);
|
|
734
761
|
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,
|
|
762
|
+
u <= d && (u = Math.min(d + n.duration, n.max)), !(u <= d) && this.cal.commitSelect(this.timeAt(d), this.timeAt(u), e, c);
|
|
736
763
|
}
|
|
737
764
|
});
|
|
738
765
|
});
|
|
@@ -773,10 +800,10 @@ const M = {
|
|
|
773
800
|
}, j = { start: "", center: "title", end: "today prev next" };
|
|
774
801
|
class Q {
|
|
775
802
|
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(
|
|
803
|
+
this.viewImpl = null, this.bodyEl = null, this.titleEl = null, this.resourceRenderScheduled = !1, this.el = t, this.options = e, this.events = new _(e.timezone), this.resources = new X(
|
|
777
804
|
e.resourceGroupField ?? "group",
|
|
778
805
|
e.resourceOrder ?? "order"
|
|
779
|
-
), this._view = e.view ?? "day", this._date = e.date ? b(e.date, e.timezone) :
|
|
806
|
+
), this._view = e.view ?? "day", this._date = e.date ? b(e.date, e.timezone) : P(e.timezone), Array.isArray(e.resources) && this.resources.set(e.resources), Array.isArray(e.events) && this.events.set(e.events);
|
|
780
807
|
}
|
|
781
808
|
// ---- derived state -------------------------------------------------------
|
|
782
809
|
get tz() {
|
|
@@ -813,7 +840,7 @@ class Q {
|
|
|
813
840
|
var t;
|
|
814
841
|
return ((t = this.viewImpl) == null ? void 0 : t.range().end) ?? this._date.endOf("day");
|
|
815
842
|
}
|
|
816
|
-
/** The active view's type and date window
|
|
843
|
+
/** The active view's type and date window. */
|
|
817
844
|
getView() {
|
|
818
845
|
return { type: this._view, activeStart: this.activeStart, activeEnd: this.activeEnd };
|
|
819
846
|
}
|
|
@@ -828,7 +855,7 @@ class Q {
|
|
|
828
855
|
return this.options.selectable === !0;
|
|
829
856
|
}
|
|
830
857
|
now() {
|
|
831
|
-
return
|
|
858
|
+
return P(this.tz);
|
|
832
859
|
}
|
|
833
860
|
// ---- lifecycle -----------------------------------------------------------
|
|
834
861
|
render() {
|
|
@@ -848,7 +875,7 @@ class Q {
|
|
|
848
875
|
case "resource-day":
|
|
849
876
|
return new V(this, e);
|
|
850
877
|
case "timeline":
|
|
851
|
-
return new
|
|
878
|
+
return new U(this, e);
|
|
852
879
|
default:
|
|
853
880
|
throw new Error(`[@ziix/calendar] unknown view: ${String(t)}`);
|
|
854
881
|
}
|
|
@@ -909,17 +936,27 @@ class Q {
|
|
|
909
936
|
const e = this.resources.get(t);
|
|
910
937
|
return e ? this.resourceHandle(e) : null;
|
|
911
938
|
}
|
|
939
|
+
/**
|
|
940
|
+
* Coalesce resource-area re-renders: many setExtendedProp calls in a row (e.g.
|
|
941
|
+
* pushing work hours / punch-ins for every resource) collapse into a single
|
|
942
|
+
* cell update on the next microtask, and event bars are never rebuilt — so the
|
|
943
|
+
* timeline doesn't flicker.
|
|
944
|
+
*/
|
|
945
|
+
scheduleResourceRender() {
|
|
946
|
+
this.resourceRenderScheduled || (this.resourceRenderScheduled = !0, queueMicrotask(() => {
|
|
947
|
+
var t, e;
|
|
948
|
+
this.resourceRenderScheduled = !1, (t = this.viewImpl) != null && t.renderResources ? this.viewImpl.renderResources() : (e = this.viewImpl) == null || e.renderEvents();
|
|
949
|
+
}));
|
|
950
|
+
}
|
|
912
951
|
resourceHandle(t) {
|
|
913
952
|
return {
|
|
914
953
|
id: t.id,
|
|
915
954
|
resource: t,
|
|
916
955
|
setExtendedProp: (e, i) => {
|
|
917
|
-
|
|
918
|
-
t.extendedProps[e] = i, (n = this.viewImpl) == null || n.renderEvents();
|
|
956
|
+
t.extendedProps[e] = i, this.scheduleResourceRender();
|
|
919
957
|
},
|
|
920
958
|
setProp: (e, i) => {
|
|
921
|
-
|
|
922
|
-
e === "title" ? t.title = i : t.group = i, (n = this.viewImpl) == null || n.renderEvents();
|
|
959
|
+
e === "title" ? t.title = i : t.group = i, this.scheduleResourceRender();
|
|
923
960
|
}
|
|
924
961
|
};
|
|
925
962
|
}
|
|
@@ -988,11 +1025,11 @@ class Q {
|
|
|
988
1025
|
* preview by re-rendering) when the move is rejected.
|
|
989
1026
|
*/
|
|
990
1027
|
commitEventChange(t, e, i, n) {
|
|
991
|
-
var
|
|
1028
|
+
var a, c, l, d, u;
|
|
992
1029
|
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
1030
|
return (a = this.viewImpl) == null || a.renderEvents(), !1;
|
|
1031
|
+
if (!this.allowsOverlap() && this.hasCollision(t, e, i, n))
|
|
1032
|
+
return (c = this.viewImpl) == null || c.renderEvents(), !1;
|
|
996
1033
|
const o = { ...t };
|
|
997
1034
|
t.start = e, t.end = i, t.resourceId = n, (l = this.viewImpl) == null || l.renderEvents();
|
|
998
1035
|
const r = () => {
|
|
@@ -1022,10 +1059,10 @@ class Q {
|
|
|
1022
1059
|
n.appendChild(this.renderToolbarToken("title"));
|
|
1023
1060
|
continue;
|
|
1024
1061
|
}
|
|
1025
|
-
const
|
|
1026
|
-
|
|
1027
|
-
for (const
|
|
1028
|
-
n.appendChild(
|
|
1062
|
+
const a = document.createElement("div");
|
|
1063
|
+
a.className = "zc-btn-group";
|
|
1064
|
+
for (const c of r) a.appendChild(this.renderToolbarToken(c));
|
|
1065
|
+
n.appendChild(a);
|
|
1029
1066
|
}
|
|
1030
1067
|
e.appendChild(n);
|
|
1031
1068
|
}
|
|
@@ -1075,9 +1112,9 @@ export {
|
|
|
1075
1112
|
f as dayMinutes,
|
|
1076
1113
|
L as intlFormat,
|
|
1077
1114
|
A as minutesToTime,
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1115
|
+
P as nowTz,
|
|
1116
|
+
S as packEvents,
|
|
1117
|
+
$ as timeToMinutes,
|
|
1081
1118
|
b as toTz
|
|
1082
1119
|
};
|
|
1083
1120
|
//# sourceMappingURL=ziix-calendar.js.map
|