@super-calendar/dom 2.6.0 → 2.8.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/dist/index.d.mts +111 -16
- package/dist/index.d.ts +111 -16
- package/dist/index.js +811 -250
- package/dist/index.mjs +783 -252
- package/package.json +2 -2
- package/src/Agenda.tsx +5 -2
- package/src/Calendar.tsx +42 -0
- package/src/MonthList.tsx +3 -1
- package/src/MonthView.tsx +441 -174
- package/src/ResourceTimeline.tsx +286 -24
- package/src/TimeGrid.tsx +427 -87
- package/src/YearView.tsx +14 -4
- package/src/index.ts +8 -0
package/src/ResourceTimeline.tsx
CHANGED
|
@@ -4,10 +4,16 @@ import type {
|
|
|
4
4
|
CSSProperties,
|
|
5
5
|
PointerEvent as ReactPointerEvent,
|
|
6
6
|
ReactElement,
|
|
7
|
+
ReactNode,
|
|
7
8
|
} from "react";
|
|
8
9
|
import { useMemo, useRef, useState } from "react";
|
|
9
10
|
import {
|
|
11
|
+
backgroundBandsForDay,
|
|
12
|
+
type BusinessHoursBand,
|
|
13
|
+
type BusinessHoursValue,
|
|
10
14
|
type CalendarEvent,
|
|
15
|
+
isSameCalendarDay,
|
|
16
|
+
useNow,
|
|
11
17
|
cellRangeFromDrag,
|
|
12
18
|
closedHourBands,
|
|
13
19
|
eventTimeLabel,
|
|
@@ -31,8 +37,10 @@ export type ResourceTimelineSlot =
|
|
|
31
37
|
| "track"
|
|
32
38
|
| "gridLines"
|
|
33
39
|
| "businessHours"
|
|
40
|
+
| "backgroundEvent"
|
|
34
41
|
| "event"
|
|
35
42
|
| "eventBox"
|
|
43
|
+
| "nowIndicator"
|
|
36
44
|
| "createGhost";
|
|
37
45
|
|
|
38
46
|
/** A schedulable lane (room, person, machine) that events are grouped under. */
|
|
@@ -69,6 +77,19 @@ export interface ResourceTimelineProps<T = unknown> extends SlotStyleProps<Resou
|
|
|
69
77
|
orientation?: "horizontal" | "vertical";
|
|
70
78
|
/** The resource lanes: rows when horizontal, columns when vertical. */
|
|
71
79
|
resources: Resource[];
|
|
80
|
+
/**
|
|
81
|
+
* Cap the number of lanes shown at once; the rest sit on further pages. Pair
|
|
82
|
+
* with `resourcePage` and your own prev/next controls to page through them
|
|
83
|
+
* (like `date` drives the time axis). Omit to show every lane, sharing the
|
|
84
|
+
* available space.
|
|
85
|
+
*/
|
|
86
|
+
resourcesPerPage?: number;
|
|
87
|
+
/**
|
|
88
|
+
* The 0-based page of lanes to show when `resourcesPerPage` is set (default
|
|
89
|
+
* 0, clamped to the last page). Controlled: update it from your own paging
|
|
90
|
+
* controls.
|
|
91
|
+
*/
|
|
92
|
+
resourcePage?: number;
|
|
72
93
|
/** Events; each is placed in the row named by `resourceId(event)`. */
|
|
73
94
|
events: CalendarEvent<T>[];
|
|
74
95
|
/** Read an event's resource id. Default: `event.resourceId`. */
|
|
@@ -97,7 +118,12 @@ export interface ResourceTimelineProps<T = unknown> extends SlotStyleProps<Resou
|
|
|
97
118
|
* Enables drag-to-move and edge-resize along the time axis; called with the
|
|
98
119
|
* proposed new start/end. Return `false` to reject the drop (it snaps back).
|
|
99
120
|
*/
|
|
100
|
-
onDragEvent?: (
|
|
121
|
+
onDragEvent?: (
|
|
122
|
+
event: CalendarEvent<T>,
|
|
123
|
+
start: Date,
|
|
124
|
+
end: Date,
|
|
125
|
+
resource: Resource,
|
|
126
|
+
) => void | boolean;
|
|
101
127
|
/** Tap empty lane space; called with the snapped time and the lane's resource. */
|
|
102
128
|
onPressCell?: (at: Date, resource: Resource) => void;
|
|
103
129
|
/** Drag empty lane space to create; called with the swept start/end and the lane's resource. */
|
|
@@ -107,9 +133,30 @@ export interface ResourceTimelineProps<T = unknown> extends SlotStyleProps<Resou
|
|
|
107
133
|
* `businessHours` plus the lane's resource, so per-resource opening hours work
|
|
108
134
|
* (return `null` for a fully closed lane). A date-only function is accepted.
|
|
109
135
|
*/
|
|
110
|
-
businessHours?: (date: Date, resource: Resource) =>
|
|
136
|
+
businessHours?: (date: Date, resource: Resource) => BusinessHoursValue;
|
|
137
|
+
/**
|
|
138
|
+
* Render a closed-hours band's content yourself (a label, icon, pattern). The
|
|
139
|
+
* board keeps positioning the band; when set, the themed tint is dropped and
|
|
140
|
+
* your output fills the band instead. Receives the lane's resource. Decorative only: the
|
|
141
|
+
* band stays non-interactive and hidden from assistive tech.
|
|
142
|
+
*/
|
|
143
|
+
renderBusinessHours?: (band: BusinessHoursBand & { resource: Resource }) => ReactNode;
|
|
144
|
+
/**
|
|
145
|
+
* Render each resource's header cell yourself (an avatar, a subtitle, a status
|
|
146
|
+
* dot). Receives the resource and its index; return the cell's content. The board
|
|
147
|
+
* keeps the header cell's sizing so columns stay aligned, so this replaces only
|
|
148
|
+
* the label content. Falls back to the resource title (or id). Applies to both
|
|
149
|
+
* orientations: the top header cells when vertical, the row labels when horizontal.
|
|
150
|
+
*/
|
|
151
|
+
renderResourceHeader?: (resource: Resource, index: number) => ReactNode;
|
|
111
152
|
/** Snap dragged events to this many minutes (default 15). */
|
|
112
153
|
dragStepMinutes?: number;
|
|
154
|
+
/** Show the current-time line when `date` is today (default true). */
|
|
155
|
+
showNowIndicator?: boolean;
|
|
156
|
+
/** Fixed "now" instant for the indicator (doesn't tick). Defaults to the device clock. */
|
|
157
|
+
now?: Date;
|
|
158
|
+
/** Shift the now indicator into this IANA zone (pair with `eventsInTimeZone`). */
|
|
159
|
+
timeZone?: string;
|
|
113
160
|
/** Class applied to the root element. */
|
|
114
161
|
className?: string;
|
|
115
162
|
/** Inline styles applied to the root element. */
|
|
@@ -123,9 +170,13 @@ const GUTTER_WIDTH = 56;
|
|
|
123
170
|
|
|
124
171
|
type DragState = {
|
|
125
172
|
key: string;
|
|
173
|
+
/** The lane the drag started in, so its row can be lifted while dragging. */
|
|
174
|
+
resourceId: string;
|
|
126
175
|
kind: "move" | "resize";
|
|
127
176
|
startHours: number;
|
|
128
177
|
durationHours: number;
|
|
178
|
+
/** Live cross-axis offset (px) of a move, for the follow-the-pointer ghost. */
|
|
179
|
+
crossPx: number;
|
|
129
180
|
moved: boolean;
|
|
130
181
|
};
|
|
131
182
|
|
|
@@ -198,7 +249,9 @@ function DefaultBar<T>({
|
|
|
198
249
|
export function ResourceTimeline<T = unknown>({
|
|
199
250
|
date,
|
|
200
251
|
orientation = "horizontal",
|
|
201
|
-
resources,
|
|
252
|
+
resources: allResources,
|
|
253
|
+
resourcesPerPage,
|
|
254
|
+
resourcePage = 0,
|
|
202
255
|
events,
|
|
203
256
|
resourceId = (event) => (event as { resourceId?: string }).resourceId,
|
|
204
257
|
startHour = 0,
|
|
@@ -215,12 +268,24 @@ export function ResourceTimeline<T = unknown>({
|
|
|
215
268
|
onPressCell,
|
|
216
269
|
onCreateEvent,
|
|
217
270
|
businessHours,
|
|
271
|
+
renderBusinessHours,
|
|
272
|
+
renderResourceHeader,
|
|
218
273
|
dragStepMinutes = 15,
|
|
274
|
+
showNowIndicator = true,
|
|
275
|
+
now: nowProp,
|
|
276
|
+
timeZone,
|
|
219
277
|
className,
|
|
220
278
|
style,
|
|
221
279
|
classNames,
|
|
222
280
|
styles,
|
|
223
281
|
}: ResourceTimelineProps<T>): ReactElement {
|
|
282
|
+
// Window the lanes to the requested page when resourcesPerPage caps them.
|
|
283
|
+
const resources = useMemo(() => {
|
|
284
|
+
if (!resourcesPerPage || resourcesPerPage <= 0) return allResources;
|
|
285
|
+
const pages = Math.max(1, Math.ceil(allResources.length / resourcesPerPage));
|
|
286
|
+
const page = Math.min(Math.max(resourcePage, 0), pages - 1);
|
|
287
|
+
return allResources.slice(page * resourcesPerPage, (page + 1) * resourcesPerPage);
|
|
288
|
+
}, [allResources, resourcesPerPage, resourcePage]);
|
|
224
289
|
const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
|
|
225
290
|
const slot = createSlots<ResourceTimelineSlot>({ classNames, styles });
|
|
226
291
|
const Renderer = renderEvent;
|
|
@@ -228,12 +293,54 @@ export function ResourceTimeline<T = unknown>({
|
|
|
228
293
|
const vertical = orientation === "vertical";
|
|
229
294
|
// Pixels per hour along whichever axis carries the time.
|
|
230
295
|
const hourSize = vertical ? hourHeight : hourWidth;
|
|
296
|
+
// The current-time line, shown only when the board's day is the zone's today.
|
|
297
|
+
const now = useNow(showNowIndicator, { now: nowProp, timeZone });
|
|
298
|
+
const nowHours = now.getHours() + now.getMinutes() / 60;
|
|
299
|
+
const showNow =
|
|
300
|
+
showNowIndicator &&
|
|
301
|
+
isSameCalendarDay(now, date) &&
|
|
302
|
+
nowHours >= startHour &&
|
|
303
|
+
nowHours <= endHour;
|
|
304
|
+
const nowLine = (resourceKey: string) =>
|
|
305
|
+
showNow ? (
|
|
306
|
+
<div
|
|
307
|
+
key={`now-${resourceKey}`}
|
|
308
|
+
aria-hidden
|
|
309
|
+
{...slot("nowIndicator", {
|
|
310
|
+
base: vertical
|
|
311
|
+
? {
|
|
312
|
+
position: "absolute",
|
|
313
|
+
left: 0,
|
|
314
|
+
right: 0,
|
|
315
|
+
top: (nowHours - startHour) * hourSize,
|
|
316
|
+
height: 2,
|
|
317
|
+
pointerEvents: "none",
|
|
318
|
+
zIndex: 2,
|
|
319
|
+
}
|
|
320
|
+
: {
|
|
321
|
+
position: "absolute",
|
|
322
|
+
top: 0,
|
|
323
|
+
bottom: 0,
|
|
324
|
+
left: (nowHours - startHour) * hourSize,
|
|
325
|
+
width: 2,
|
|
326
|
+
pointerEvents: "none",
|
|
327
|
+
zIndex: 2,
|
|
328
|
+
},
|
|
329
|
+
themed: { background: theme.nowIndicator },
|
|
330
|
+
})}
|
|
331
|
+
/>
|
|
332
|
+
) : null;
|
|
231
333
|
|
|
232
334
|
// `drag` drives the visual; `dragRef` is the source of truth the pointer
|
|
233
335
|
// handlers read so they never see a stale closure between events.
|
|
234
336
|
const [drag, setDrag] = useState<DragState | null>(null);
|
|
235
337
|
const dragRef = useRef<DragState | null>(null);
|
|
236
|
-
const origin = useRef<{
|
|
338
|
+
const origin = useRef<{
|
|
339
|
+
x: number;
|
|
340
|
+
cross: number;
|
|
341
|
+
startHours: number;
|
|
342
|
+
durationHours: number;
|
|
343
|
+
} | null>(null);
|
|
237
344
|
const applyDrag = (next: DragState | null) => {
|
|
238
345
|
dragRef.current = next;
|
|
239
346
|
setDrag(next);
|
|
@@ -242,6 +349,7 @@ export function ResourceTimeline<T = unknown>({
|
|
|
242
349
|
const beginDrag = (
|
|
243
350
|
e: ReactPointerEvent,
|
|
244
351
|
key: string,
|
|
352
|
+
resourceId: string,
|
|
245
353
|
kind: "move" | "resize",
|
|
246
354
|
startHours: number,
|
|
247
355
|
durationHours: number,
|
|
@@ -253,8 +361,13 @@ export function ResourceTimeline<T = unknown>({
|
|
|
253
361
|
} catch {
|
|
254
362
|
// Pointer capture is best-effort.
|
|
255
363
|
}
|
|
256
|
-
origin.current = {
|
|
257
|
-
|
|
364
|
+
origin.current = {
|
|
365
|
+
x: vertical ? e.clientY : e.clientX,
|
|
366
|
+
cross: vertical ? e.clientX : e.clientY,
|
|
367
|
+
startHours,
|
|
368
|
+
durationHours,
|
|
369
|
+
};
|
|
370
|
+
applyDrag({ key, resourceId, kind, startHours, durationHours, crossPx: 0, moved: false });
|
|
258
371
|
};
|
|
259
372
|
const moveDrag = (e: ReactPointerEvent) => {
|
|
260
373
|
const d = dragRef.current;
|
|
@@ -267,7 +380,8 @@ export function ResourceTimeline<T = unknown>({
|
|
|
267
380
|
startHour,
|
|
268
381
|
endHour - d.durationHours,
|
|
269
382
|
);
|
|
270
|
-
|
|
383
|
+
const crossPx = (vertical ? e.clientX : e.clientY) - origin.current.cross;
|
|
384
|
+
applyDrag({ ...d, startHours, crossPx, moved: true });
|
|
271
385
|
} else {
|
|
272
386
|
const durationHours = clamp(
|
|
273
387
|
snap(origin.current.durationHours + dHours),
|
|
@@ -277,7 +391,35 @@ export function ResourceTimeline<T = unknown>({
|
|
|
277
391
|
applyDrag({ ...d, durationHours, moved: true });
|
|
278
392
|
}
|
|
279
393
|
};
|
|
280
|
-
|
|
394
|
+
// Which visible lane the pointer is over, found by hit-testing rather than
|
|
395
|
+
// measuring flexed columns. The dragged bar is momentarily made
|
|
396
|
+
// pointer-transparent so `elementFromPoint` sees the lane, not the bar (which
|
|
397
|
+
// stays a DOM child of its origin lane however far it's visually translated).
|
|
398
|
+
const laneAt = (e: ReactPointerEvent, fallback: Resource): Resource => {
|
|
399
|
+
if (typeof document === "undefined" || typeof document.elementFromPoint !== "function") {
|
|
400
|
+
return fallback;
|
|
401
|
+
}
|
|
402
|
+
const bar = e.currentTarget as HTMLElement;
|
|
403
|
+
const prev = bar.style.pointerEvents;
|
|
404
|
+
// Restore in a finally: a left-behind "none" would permanently disable this
|
|
405
|
+
// bar, since React never re-manages this imperatively-set inline style.
|
|
406
|
+
let hit: Element | null;
|
|
407
|
+
bar.style.pointerEvents = "none";
|
|
408
|
+
try {
|
|
409
|
+
hit = document.elementFromPoint(e.clientX, e.clientY);
|
|
410
|
+
} finally {
|
|
411
|
+
bar.style.pointerEvents = prev;
|
|
412
|
+
}
|
|
413
|
+
const laneEl = (hit as HTMLElement | null)?.closest?.("[data-resource-id]");
|
|
414
|
+
const id = laneEl?.getAttribute("data-resource-id");
|
|
415
|
+
return (id && resources.find((r) => r.id === id)) || fallback;
|
|
416
|
+
};
|
|
417
|
+
const endDrag = (
|
|
418
|
+
e: ReactPointerEvent,
|
|
419
|
+
event: CalendarEvent<T>,
|
|
420
|
+
resource: Resource,
|
|
421
|
+
onPress: () => void,
|
|
422
|
+
) => {
|
|
281
423
|
const d = dragRef.current;
|
|
282
424
|
if (!d) return;
|
|
283
425
|
try {
|
|
@@ -290,10 +432,11 @@ export function ResourceTimeline<T = unknown>({
|
|
|
290
432
|
onPress();
|
|
291
433
|
return;
|
|
292
434
|
}
|
|
435
|
+
const target = d.kind === "move" ? laneAt(e, resource) : resource;
|
|
293
436
|
const base = startOfDay(date);
|
|
294
437
|
const start = addMinutes(base, Math.round(d.startHours * 60));
|
|
295
438
|
const end = addMinutes(base, Math.round((d.startHours + d.durationHours) * 60));
|
|
296
|
-
onDragEvent?.(event, start, end);
|
|
439
|
+
onDragEvent?.(event, start, end, target);
|
|
297
440
|
applyDrag(null);
|
|
298
441
|
origin.current = null;
|
|
299
442
|
};
|
|
@@ -385,6 +528,18 @@ export function ResourceTimeline<T = unknown>({
|
|
|
385
528
|
businessHours
|
|
386
529
|
? closedHourBands(date, (d) => businessHours(d, resource), startHour, endHour)
|
|
387
530
|
: [];
|
|
531
|
+
// `display: "background"` events in a lane, clipped to the visible window.
|
|
532
|
+
const backgroundBandsFor = (resource: Resource) =>
|
|
533
|
+
backgroundBandsForDay(
|
|
534
|
+
events.filter((e) => resourceId(e) === resource.id),
|
|
535
|
+
date,
|
|
536
|
+
)
|
|
537
|
+
.map((b) => ({
|
|
538
|
+
...b,
|
|
539
|
+
startHours: Math.max(b.startHours, startHour),
|
|
540
|
+
endHours: Math.min(b.endHours, endHour),
|
|
541
|
+
}))
|
|
542
|
+
.filter((b) => b.endHours > b.startHours);
|
|
388
543
|
|
|
389
544
|
const hours = useMemo(
|
|
390
545
|
() => Array.from({ length: Math.max(0, endHour - startHour) }, (_, i) => startHour + i),
|
|
@@ -402,6 +557,10 @@ export function ResourceTimeline<T = unknown>({
|
|
|
402
557
|
return map;
|
|
403
558
|
}, [resources, events, resourceId, date]);
|
|
404
559
|
|
|
560
|
+
// The lane a move is dragging in, lifted above its siblings so the ghost
|
|
561
|
+
// stays visible as it crosses into another lane (a later DOM sibling).
|
|
562
|
+
const dragLaneId = drag?.kind === "move" && drag.moved ? drag.resourceId : null;
|
|
563
|
+
|
|
405
564
|
if (vertical) {
|
|
406
565
|
// Time flows down like the time grid: hour gutter on the left, one flexed
|
|
407
566
|
// column per resource, so narrow screens share the width instead of
|
|
@@ -423,7 +582,7 @@ export function ResourceTimeline<T = unknown>({
|
|
|
423
582
|
})}
|
|
424
583
|
>
|
|
425
584
|
<div {...slot("corner", { base: { width: GUTTER_WIDTH, flex: "none" } })} />
|
|
426
|
-
{resources.map((resource) => (
|
|
585
|
+
{resources.map((resource, index) => (
|
|
427
586
|
<div
|
|
428
587
|
key={resource.id}
|
|
429
588
|
{...slot("resourceLabel", {
|
|
@@ -444,7 +603,9 @@ export function ResourceTimeline<T = unknown>({
|
|
|
444
603
|
},
|
|
445
604
|
})}
|
|
446
605
|
>
|
|
447
|
-
{
|
|
606
|
+
{renderResourceHeader
|
|
607
|
+
? renderResourceHeader(resource, index)
|
|
608
|
+
: (resource.title ?? resource.id)}
|
|
448
609
|
</div>
|
|
449
610
|
))}
|
|
450
611
|
</div>
|
|
@@ -481,11 +642,16 @@ export function ResourceTimeline<T = unknown>({
|
|
|
481
642
|
<div
|
|
482
643
|
key={resource.id}
|
|
483
644
|
{...slot("row", {
|
|
484
|
-
base: {
|
|
645
|
+
base: {
|
|
646
|
+
flex: 1,
|
|
647
|
+
minWidth: 0,
|
|
648
|
+
...(dragLaneId === resource.id ? { position: "relative", zIndex: 5 } : null),
|
|
649
|
+
},
|
|
485
650
|
themed: { borderLeft: `1px solid ${theme.gridLine}` },
|
|
486
651
|
})}
|
|
487
652
|
>
|
|
488
653
|
<div
|
|
654
|
+
data-resource-id={resource.id}
|
|
489
655
|
{...trackInteractionProps(resource)}
|
|
490
656
|
{...slot("track", { base: { position: "relative", height: trackHeight } })}
|
|
491
657
|
>
|
|
@@ -504,7 +670,30 @@ export function ResourceTimeline<T = unknown>({
|
|
|
504
670
|
pointerEvents: "none",
|
|
505
671
|
zIndex: 0,
|
|
506
672
|
},
|
|
507
|
-
themed:
|
|
673
|
+
themed: renderBusinessHours
|
|
674
|
+
? undefined
|
|
675
|
+
: { background: theme.outsideHoursBackground },
|
|
676
|
+
})}
|
|
677
|
+
>
|
|
678
|
+
{renderBusinessHours?.({ date, start: b.start, end: b.end, resource })}
|
|
679
|
+
</div>
|
|
680
|
+
))}
|
|
681
|
+
{backgroundBandsFor(resource).map((b, i) => (
|
|
682
|
+
<div
|
|
683
|
+
key={`bg-${i}`}
|
|
684
|
+
aria-hidden
|
|
685
|
+
title={b.event.title}
|
|
686
|
+
{...slot("backgroundEvent", {
|
|
687
|
+
base: {
|
|
688
|
+
position: "absolute",
|
|
689
|
+
left: 0,
|
|
690
|
+
right: 0,
|
|
691
|
+
top: (b.startHours - startHour) * hourHeight,
|
|
692
|
+
height: (b.endHours - b.startHours) * hourHeight,
|
|
693
|
+
pointerEvents: "none",
|
|
694
|
+
zIndex: 0,
|
|
695
|
+
},
|
|
696
|
+
themed: { background: theme.backgroundEvent },
|
|
508
697
|
})}
|
|
509
698
|
/>
|
|
510
699
|
))}
|
|
@@ -533,7 +722,8 @@ export function ResourceTimeline<T = unknown>({
|
|
|
533
722
|
height,
|
|
534
723
|
onPress,
|
|
535
724
|
};
|
|
536
|
-
|
|
725
|
+
// `draggable: false` locks a single bar (keeps clicks, blocks drag).
|
|
726
|
+
const draggable = !!onDragEvent && pe.event.draggable !== false;
|
|
537
727
|
return (
|
|
538
728
|
<button
|
|
539
729
|
key={idx}
|
|
@@ -543,11 +733,21 @@ export function ResourceTimeline<T = unknown>({
|
|
|
543
733
|
{...dataState({ "data-dragging": !!active })}
|
|
544
734
|
onPointerDown={
|
|
545
735
|
draggable
|
|
546
|
-
? (e) =>
|
|
736
|
+
? (e) =>
|
|
737
|
+
beginDrag(
|
|
738
|
+
e,
|
|
739
|
+
key,
|
|
740
|
+
resource.id,
|
|
741
|
+
"move",
|
|
742
|
+
pe.startHours,
|
|
743
|
+
pe.durationHours,
|
|
744
|
+
)
|
|
547
745
|
: undefined
|
|
548
746
|
}
|
|
549
747
|
onPointerMove={draggable ? moveDrag : undefined}
|
|
550
|
-
onPointerUp={
|
|
748
|
+
onPointerUp={
|
|
749
|
+
draggable ? (e) => endDrag(e, pe.event, resource, onPress) : undefined
|
|
750
|
+
}
|
|
551
751
|
onPointerCancel={draggable ? cancelDrag : undefined}
|
|
552
752
|
{...slot("event", {
|
|
553
753
|
base: {
|
|
@@ -556,6 +756,10 @@ export function ResourceTimeline<T = unknown>({
|
|
|
556
756
|
height,
|
|
557
757
|
left: `${pe.column * lanePct}%`,
|
|
558
758
|
width: `${lanePct}%`,
|
|
759
|
+
transform:
|
|
760
|
+
active?.kind === "move"
|
|
761
|
+
? `translateX(${active.crossPx}px)`
|
|
762
|
+
: undefined,
|
|
559
763
|
padding: 1,
|
|
560
764
|
border: "none",
|
|
561
765
|
background: "transparent",
|
|
@@ -579,7 +783,14 @@ export function ResourceTimeline<T = unknown>({
|
|
|
579
783
|
aria-hidden
|
|
580
784
|
onPointerDown={(e) => {
|
|
581
785
|
e.stopPropagation();
|
|
582
|
-
beginDrag(
|
|
786
|
+
beginDrag(
|
|
787
|
+
e,
|
|
788
|
+
key,
|
|
789
|
+
resource.id,
|
|
790
|
+
"resize",
|
|
791
|
+
pe.startHours,
|
|
792
|
+
pe.durationHours,
|
|
793
|
+
);
|
|
583
794
|
}}
|
|
584
795
|
style={{
|
|
585
796
|
position: "absolute",
|
|
@@ -595,6 +806,7 @@ export function ResourceTimeline<T = unknown>({
|
|
|
595
806
|
</button>
|
|
596
807
|
);
|
|
597
808
|
})}
|
|
809
|
+
{nowLine(resource.id)}
|
|
598
810
|
{createBox?.resourceKey === resource.id ? (
|
|
599
811
|
<div
|
|
600
812
|
aria-hidden
|
|
@@ -660,13 +872,17 @@ export function ResourceTimeline<T = unknown>({
|
|
|
660
872
|
</div>
|
|
661
873
|
|
|
662
874
|
{/* Resource rows */}
|
|
663
|
-
{resources.map((resource) => {
|
|
875
|
+
{resources.map((resource, index) => {
|
|
664
876
|
const positioned = byResource.get(resource.id) ?? [];
|
|
665
877
|
return (
|
|
666
878
|
<div
|
|
667
879
|
key={resource.id}
|
|
668
880
|
{...slot("row", {
|
|
669
|
-
base: {
|
|
881
|
+
base: {
|
|
882
|
+
display: "flex",
|
|
883
|
+
height: rowHeight,
|
|
884
|
+
...(dragLaneId === resource.id ? { position: "relative", zIndex: 5 } : null),
|
|
885
|
+
},
|
|
670
886
|
themed: { borderBottom: `1px solid ${theme.gridLine}` },
|
|
671
887
|
})}
|
|
672
888
|
>
|
|
@@ -687,9 +903,12 @@ export function ResourceTimeline<T = unknown>({
|
|
|
687
903
|
},
|
|
688
904
|
})}
|
|
689
905
|
>
|
|
690
|
-
{
|
|
906
|
+
{renderResourceHeader
|
|
907
|
+
? renderResourceHeader(resource, index)
|
|
908
|
+
: (resource.title ?? resource.id)}
|
|
691
909
|
</div>
|
|
692
910
|
<div
|
|
911
|
+
data-resource-id={resource.id}
|
|
693
912
|
{...trackInteractionProps(resource)}
|
|
694
913
|
{...slot("track", { base: { position: "relative", width: trackWidth } })}
|
|
695
914
|
>
|
|
@@ -708,7 +927,30 @@ export function ResourceTimeline<T = unknown>({
|
|
|
708
927
|
pointerEvents: "none",
|
|
709
928
|
zIndex: 0,
|
|
710
929
|
},
|
|
711
|
-
themed:
|
|
930
|
+
themed: renderBusinessHours
|
|
931
|
+
? undefined
|
|
932
|
+
: { background: theme.outsideHoursBackground },
|
|
933
|
+
})}
|
|
934
|
+
>
|
|
935
|
+
{renderBusinessHours?.({ date, start: b.start, end: b.end, resource })}
|
|
936
|
+
</div>
|
|
937
|
+
))}
|
|
938
|
+
{backgroundBandsFor(resource).map((b, i) => (
|
|
939
|
+
<div
|
|
940
|
+
key={`bg-${i}`}
|
|
941
|
+
aria-hidden
|
|
942
|
+
title={b.event.title}
|
|
943
|
+
{...slot("backgroundEvent", {
|
|
944
|
+
base: {
|
|
945
|
+
position: "absolute",
|
|
946
|
+
top: 0,
|
|
947
|
+
bottom: 0,
|
|
948
|
+
left: (b.startHours - startHour) * hourWidth,
|
|
949
|
+
width: (b.endHours - b.startHours) * hourWidth,
|
|
950
|
+
pointerEvents: "none",
|
|
951
|
+
zIndex: 0,
|
|
952
|
+
},
|
|
953
|
+
themed: { background: theme.backgroundEvent },
|
|
712
954
|
})}
|
|
713
955
|
/>
|
|
714
956
|
))}
|
|
@@ -742,11 +984,21 @@ export function ResourceTimeline<T = unknown>({
|
|
|
742
984
|
{...dataState({ "data-dragging": !!active })}
|
|
743
985
|
onPointerDown={
|
|
744
986
|
draggable
|
|
745
|
-
? (e) =>
|
|
987
|
+
? (e) =>
|
|
988
|
+
beginDrag(
|
|
989
|
+
e,
|
|
990
|
+
key,
|
|
991
|
+
resource.id,
|
|
992
|
+
"move",
|
|
993
|
+
pe.startHours,
|
|
994
|
+
pe.durationHours,
|
|
995
|
+
)
|
|
746
996
|
: undefined
|
|
747
997
|
}
|
|
748
998
|
onPointerMove={draggable ? moveDrag : undefined}
|
|
749
|
-
onPointerUp={
|
|
999
|
+
onPointerUp={
|
|
1000
|
+
draggable ? (e) => endDrag(e, pe.event, resource, onPress) : undefined
|
|
1001
|
+
}
|
|
750
1002
|
onPointerCancel={draggable ? cancelDrag : undefined}
|
|
751
1003
|
{...slot("event", {
|
|
752
1004
|
base: {
|
|
@@ -755,6 +1007,8 @@ export function ResourceTimeline<T = unknown>({
|
|
|
755
1007
|
width,
|
|
756
1008
|
top: pe.column * laneHeight,
|
|
757
1009
|
height: laneHeight,
|
|
1010
|
+
transform:
|
|
1011
|
+
active?.kind === "move" ? `translateY(${active.crossPx}px)` : undefined,
|
|
758
1012
|
padding: 1,
|
|
759
1013
|
border: "none",
|
|
760
1014
|
background: "transparent",
|
|
@@ -778,7 +1032,14 @@ export function ResourceTimeline<T = unknown>({
|
|
|
778
1032
|
aria-hidden
|
|
779
1033
|
onPointerDown={(e) => {
|
|
780
1034
|
e.stopPropagation();
|
|
781
|
-
beginDrag(
|
|
1035
|
+
beginDrag(
|
|
1036
|
+
e,
|
|
1037
|
+
key,
|
|
1038
|
+
resource.id,
|
|
1039
|
+
"resize",
|
|
1040
|
+
pe.startHours,
|
|
1041
|
+
pe.durationHours,
|
|
1042
|
+
);
|
|
782
1043
|
}}
|
|
783
1044
|
style={{
|
|
784
1045
|
position: "absolute",
|
|
@@ -794,6 +1055,7 @@ export function ResourceTimeline<T = unknown>({
|
|
|
794
1055
|
</button>
|
|
795
1056
|
);
|
|
796
1057
|
})}
|
|
1058
|
+
{nowLine(resource.id)}
|
|
797
1059
|
{createBox?.resourceKey === resource.id ? (
|
|
798
1060
|
<div
|
|
799
1061
|
aria-hidden
|