@vesture/react 0.3.0 → 0.3.1
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.css +307 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +46 -1
- package/dist/index.js +638 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2001,8 +2001,7 @@ var root2 = "Calendar_root__1uy43my0";
|
|
|
2001
2001
|
var weekRow = "Calendar_weekRow__1uy43my5";
|
|
2002
2002
|
var weekdayCell = "Calendar_weekdayCell__1uy43my6";
|
|
2003
2003
|
|
|
2004
|
-
// src/
|
|
2005
|
-
import { jsx as jsx35, jsxs as jsxs18 } from "react/jsx-runtime";
|
|
2004
|
+
// src/utils/date.ts
|
|
2006
2005
|
function startOfMonth(date) {
|
|
2007
2006
|
return new Date(date.getFullYear(), date.getMonth(), 1);
|
|
2008
2007
|
}
|
|
@@ -2038,6 +2037,9 @@ function endOfWeek(date, weekStartsOn) {
|
|
|
2038
2037
|
function dateKey(date) {
|
|
2039
2038
|
return `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`;
|
|
2040
2039
|
}
|
|
2040
|
+
|
|
2041
|
+
// src/components/Calendar/Calendar.tsx
|
|
2042
|
+
import { jsx as jsx35, jsxs as jsxs18 } from "react/jsx-runtime";
|
|
2041
2043
|
function getCalendarWeeks(month, weekStartsOn) {
|
|
2042
2044
|
const gridStart = startOfWeek(startOfMonth(month), weekStartsOn);
|
|
2043
2045
|
const gridEnd = endOfWeek(endOfMonth(month), weekStartsOn);
|
|
@@ -5585,8 +5587,639 @@ function InteractivePieChart({
|
|
|
5585
5587
|
] });
|
|
5586
5588
|
}
|
|
5587
5589
|
|
|
5590
|
+
// src/components/Scheduler/Scheduler.tsx
|
|
5591
|
+
import { useMemo as useMemo10, useRef as useRef12, useState as useState21 } from "react";
|
|
5592
|
+
|
|
5593
|
+
// src/components/Scheduler/Scheduler.css.ts
|
|
5594
|
+
var allDayCell = "Scheduler_allDayCell__1to95h2c";
|
|
5595
|
+
var allDayEventBlock = "Scheduler_allDayEventBlock__1to95h2o";
|
|
5596
|
+
var allDayGutter = "Scheduler_allDayGutter__1to95h2b";
|
|
5597
|
+
var allDayRow = "Scheduler_allDayRow__1to95h2a";
|
|
5598
|
+
var dayColumn = "Scheduler_dayColumn__1to95h2g";
|
|
5599
|
+
var dayHeaderCell = "Scheduler_dayHeaderCell__1to95h28";
|
|
5600
|
+
var dayHeaderDateNumber = "Scheduler_dayHeaderDateNumber__1to95h29";
|
|
5601
|
+
var dayHeaderGutter = "Scheduler_dayHeaderGutter__1to95h27";
|
|
5602
|
+
var dayHeaderRow = "Scheduler_dayHeaderRow__1to95h26";
|
|
5603
|
+
var dragPreview = "Scheduler_dragPreview__1to95h2l";
|
|
5604
|
+
var dragPreviewLabel = "Scheduler_dragPreviewLabel__1to95h2m";
|
|
5605
|
+
var eventBlock = "Scheduler_eventBlock__1to95h2j";
|
|
5606
|
+
var eventTime = "Scheduler_eventTime__1to95h2q";
|
|
5607
|
+
var eventTitle = "Scheduler_eventTitle__1to95h2p";
|
|
5608
|
+
var header2 = "Scheduler_header__1to95h21";
|
|
5609
|
+
var headerNav = "Scheduler_headerNav__1to95h22";
|
|
5610
|
+
var hourLabel = "Scheduler_hourLabel__1to95h2f";
|
|
5611
|
+
var navButton2 = "Scheduler_navButton__1to95h23";
|
|
5612
|
+
var nowLine = "Scheduler_nowLine__1to95h2h";
|
|
5613
|
+
var nowLineDot = "Scheduler_nowLineDot__1to95h2i";
|
|
5614
|
+
var rangeLabel = "Scheduler_rangeLabel__1to95h25";
|
|
5615
|
+
var resizeHandle2 = "Scheduler_resizeHandle__1to95h2k";
|
|
5616
|
+
var root9 = "Scheduler_root__1to95h20";
|
|
5617
|
+
var scrollArea = "Scheduler_scrollArea__1to95h2d";
|
|
5618
|
+
var timeGutter = "Scheduler_timeGutter__1to95h2e";
|
|
5619
|
+
var todayButton = "Scheduler_todayButton__1to95h24";
|
|
5620
|
+
var visuallyHidden = "Scheduler_visuallyHidden__1to95h2n";
|
|
5621
|
+
|
|
5622
|
+
// src/components/Scheduler/scheduler-layout.ts
|
|
5623
|
+
import { vars as vars12 } from "@vesture/tokens";
|
|
5624
|
+
var SLOT_HEIGHT_PX = 24;
|
|
5625
|
+
function layoutOverlappingEvents(events) {
|
|
5626
|
+
if (events.length === 0) return [];
|
|
5627
|
+
const sorted = [...events].sort((a, b) => {
|
|
5628
|
+
const startDiff = a.start.getTime() - b.start.getTime();
|
|
5629
|
+
if (startDiff !== 0) return startDiff;
|
|
5630
|
+
return a.end.getTime() - b.end.getTime();
|
|
5631
|
+
});
|
|
5632
|
+
const results = /* @__PURE__ */ new Map();
|
|
5633
|
+
let cluster = [];
|
|
5634
|
+
let clusterEnd = -Infinity;
|
|
5635
|
+
const flushCluster = () => {
|
|
5636
|
+
if (cluster.length === 0) return;
|
|
5637
|
+
const columnEndTimes = [];
|
|
5638
|
+
for (const event of cluster) {
|
|
5639
|
+
const startTime = event.start.getTime();
|
|
5640
|
+
let columnIndex = columnEndTimes.findIndex((end) => end <= startTime);
|
|
5641
|
+
if (columnIndex === -1) {
|
|
5642
|
+
columnIndex = columnEndTimes.length;
|
|
5643
|
+
columnEndTimes.push(event.end.getTime());
|
|
5644
|
+
} else {
|
|
5645
|
+
columnEndTimes[columnIndex] = event.end.getTime();
|
|
5646
|
+
}
|
|
5647
|
+
results.set(event.id, { id: event.id, columnIndex, columnCount: 0 });
|
|
5648
|
+
}
|
|
5649
|
+
const columnCount = columnEndTimes.length;
|
|
5650
|
+
for (const event of cluster) {
|
|
5651
|
+
results.get(event.id).columnCount = columnCount;
|
|
5652
|
+
}
|
|
5653
|
+
cluster = [];
|
|
5654
|
+
};
|
|
5655
|
+
for (const event of sorted) {
|
|
5656
|
+
const startTime = event.start.getTime();
|
|
5657
|
+
const endTime = event.end.getTime();
|
|
5658
|
+
if (cluster.length === 0 || startTime < clusterEnd) {
|
|
5659
|
+
cluster.push(event);
|
|
5660
|
+
clusterEnd = Math.max(clusterEnd, endTime);
|
|
5661
|
+
} else {
|
|
5662
|
+
flushCluster();
|
|
5663
|
+
cluster.push(event);
|
|
5664
|
+
clusterEnd = endTime;
|
|
5665
|
+
}
|
|
5666
|
+
}
|
|
5667
|
+
flushCluster();
|
|
5668
|
+
return events.map((event) => results.get(event.id));
|
|
5669
|
+
}
|
|
5670
|
+
function getVerticalMetrics(start, end, startHour, endHour) {
|
|
5671
|
+
const rangeStartMinutes = startHour * 60;
|
|
5672
|
+
const rangeEndMinutes = endHour * 60;
|
|
5673
|
+
const totalMinutes = rangeEndMinutes - rangeStartMinutes;
|
|
5674
|
+
if (totalMinutes <= 0) return null;
|
|
5675
|
+
const startMinutes = start.getHours() * 60 + start.getMinutes();
|
|
5676
|
+
const endMinutes = end.getHours() * 60 + end.getMinutes();
|
|
5677
|
+
const clippedStart = Math.max(startMinutes, rangeStartMinutes);
|
|
5678
|
+
const clippedEnd = Math.min(endMinutes, rangeEndMinutes);
|
|
5679
|
+
if (clippedEnd <= clippedStart) return null;
|
|
5680
|
+
return {
|
|
5681
|
+
top: (clippedStart - rangeStartMinutes) / totalMinutes * 100,
|
|
5682
|
+
height: (clippedEnd - clippedStart) / totalMinutes * 100
|
|
5683
|
+
};
|
|
5684
|
+
}
|
|
5685
|
+
function pixelDeltaToSnappedMinutes(deltaPx, slotDuration) {
|
|
5686
|
+
const rawSlots = deltaPx / SLOT_HEIGHT_PX;
|
|
5687
|
+
return Math.round(rawSlots) * slotDuration;
|
|
5688
|
+
}
|
|
5689
|
+
function minutesOfDay(date) {
|
|
5690
|
+
return date.getHours() * 60 + date.getMinutes();
|
|
5691
|
+
}
|
|
5692
|
+
function combineDayAndMinutes(day, minutesOfDayValue) {
|
|
5693
|
+
const result = new Date(day.getFullYear(), day.getMonth(), day.getDate());
|
|
5694
|
+
result.setMinutes(minutesOfDayValue);
|
|
5695
|
+
return result;
|
|
5696
|
+
}
|
|
5697
|
+
function computeMoveResult(params) {
|
|
5698
|
+
const { originalStart, originalEnd, targetDay, deltaYPx, slotDuration, startHour, endHour } = params;
|
|
5699
|
+
const durationMinutes = (originalEnd.getTime() - originalStart.getTime()) / 6e4;
|
|
5700
|
+
const deltaMinutes = pixelDeltaToSnappedMinutes(deltaYPx, slotDuration);
|
|
5701
|
+
const rawStartMinutes = minutesOfDay(originalStart) + deltaMinutes;
|
|
5702
|
+
const rangeStart = startHour * 60;
|
|
5703
|
+
const rangeEnd = endHour * 60;
|
|
5704
|
+
const maxStart = Math.max(rangeStart, rangeEnd - durationMinutes);
|
|
5705
|
+
const clampedStartMinutes = Math.min(Math.max(rawStartMinutes, rangeStart), maxStart);
|
|
5706
|
+
const start = combineDayAndMinutes(targetDay, clampedStartMinutes);
|
|
5707
|
+
const end = new Date(start.getTime() + durationMinutes * 6e4);
|
|
5708
|
+
return { start, end };
|
|
5709
|
+
}
|
|
5710
|
+
function computeResizeResult(params) {
|
|
5711
|
+
const { originalStart, originalEnd, deltaYPx, slotDuration, minEventDuration, endHour } = params;
|
|
5712
|
+
const deltaMinutes = pixelDeltaToSnappedMinutes(deltaYPx, slotDuration);
|
|
5713
|
+
const rawEndMinutes = minutesOfDay(originalEnd) + deltaMinutes;
|
|
5714
|
+
const startMinutes = minutesOfDay(originalStart);
|
|
5715
|
+
const rangeEnd = endHour * 60;
|
|
5716
|
+
const clampedEndMinutes = Math.min(
|
|
5717
|
+
Math.max(rawEndMinutes, startMinutes + minEventDuration),
|
|
5718
|
+
rangeEnd
|
|
5719
|
+
);
|
|
5720
|
+
const end = combineDayAndMinutes(originalStart, clampedEndMinutes);
|
|
5721
|
+
return { end };
|
|
5722
|
+
}
|
|
5723
|
+
var SERIES_COLOR_CYCLE4 = [
|
|
5724
|
+
vars12.chart.series1,
|
|
5725
|
+
vars12.chart.series2,
|
|
5726
|
+
vars12.chart.series3,
|
|
5727
|
+
vars12.chart.series4,
|
|
5728
|
+
vars12.chart.series5,
|
|
5729
|
+
vars12.chart.series6,
|
|
5730
|
+
vars12.chart.series7,
|
|
5731
|
+
vars12.chart.series8
|
|
5732
|
+
];
|
|
5733
|
+
function hashStringToIndex(value, bucketCount) {
|
|
5734
|
+
let hash = 5381;
|
|
5735
|
+
for (let i = 0; i < value.length; i++) {
|
|
5736
|
+
hash = hash * 33 ^ value.charCodeAt(i);
|
|
5737
|
+
}
|
|
5738
|
+
return Math.abs(hash) % bucketCount;
|
|
5739
|
+
}
|
|
5740
|
+
function getEventColor(id, override) {
|
|
5741
|
+
if (override) return override;
|
|
5742
|
+
return SERIES_COLOR_CYCLE4[hashStringToIndex(id, SERIES_COLOR_CYCLE4.length)];
|
|
5743
|
+
}
|
|
5744
|
+
|
|
5745
|
+
// src/components/Scheduler/Scheduler.tsx
|
|
5746
|
+
import { jsx as jsx51, jsxs as jsxs34 } from "react/jsx-runtime";
|
|
5747
|
+
function formatEventTime(date, locale) {
|
|
5748
|
+
return new Intl.DateTimeFormat(locale, {
|
|
5749
|
+
hour: "numeric",
|
|
5750
|
+
minute: "2-digit"
|
|
5751
|
+
}).format(date);
|
|
5752
|
+
}
|
|
5753
|
+
function Scheduler({
|
|
5754
|
+
events,
|
|
5755
|
+
date,
|
|
5756
|
+
onDateChange,
|
|
5757
|
+
weekStartsOn = 1,
|
|
5758
|
+
startHour = 0,
|
|
5759
|
+
endHour = 24,
|
|
5760
|
+
slotDuration = 30,
|
|
5761
|
+
onEventClick,
|
|
5762
|
+
onEventChange,
|
|
5763
|
+
editable = false,
|
|
5764
|
+
minEventDuration,
|
|
5765
|
+
selectedEventId,
|
|
5766
|
+
locale = "en-US",
|
|
5767
|
+
className
|
|
5768
|
+
}) {
|
|
5769
|
+
const weekStart = useMemo10(
|
|
5770
|
+
() => startOfWeek(clampToMidnight(date), weekStartsOn),
|
|
5771
|
+
[date, weekStartsOn]
|
|
5772
|
+
);
|
|
5773
|
+
const days = useMemo10(
|
|
5774
|
+
() => Array.from({ length: 7 }, (_, i) => addDays(weekStart, i)),
|
|
5775
|
+
[weekStart]
|
|
5776
|
+
);
|
|
5777
|
+
const today = useMemo10(() => clampToMidnight(/* @__PURE__ */ new Date()), []);
|
|
5778
|
+
const now = useMemo10(() => /* @__PURE__ */ new Date(), []);
|
|
5779
|
+
const weekdayFormatter = useMemo10(
|
|
5780
|
+
() => new Intl.DateTimeFormat(locale, { weekday: "short" }),
|
|
5781
|
+
[locale]
|
|
5782
|
+
);
|
|
5783
|
+
const dayNumberFormatter = useMemo10(
|
|
5784
|
+
() => new Intl.DateTimeFormat(locale, { day: "numeric" }),
|
|
5785
|
+
[locale]
|
|
5786
|
+
);
|
|
5787
|
+
const monthDayFormatter = useMemo10(
|
|
5788
|
+
() => new Intl.DateTimeFormat(locale, { month: "short", day: "numeric" }),
|
|
5789
|
+
[locale]
|
|
5790
|
+
);
|
|
5791
|
+
const yearFormatter = useMemo10(
|
|
5792
|
+
() => new Intl.DateTimeFormat(locale, { year: "numeric" }),
|
|
5793
|
+
[locale]
|
|
5794
|
+
);
|
|
5795
|
+
const hourFormatter = useMemo10(
|
|
5796
|
+
() => new Intl.DateTimeFormat(locale, { hour: "numeric" }),
|
|
5797
|
+
[locale]
|
|
5798
|
+
);
|
|
5799
|
+
const weekdayLongFormatter = useMemo10(
|
|
5800
|
+
() => new Intl.DateTimeFormat(locale, { weekday: "long" }),
|
|
5801
|
+
[locale]
|
|
5802
|
+
);
|
|
5803
|
+
const weekEnd = days[6];
|
|
5804
|
+
const rangeLabelText = `${monthDayFormatter.format(weekStart)} \u2013 ${monthDayFormatter.format(weekEnd)}, ${yearFormatter.format(weekEnd)}`;
|
|
5805
|
+
const totalMinutes = (endHour - startHour) * 60;
|
|
5806
|
+
const slotsCount = Math.max(1, Math.ceil(totalMinutes / slotDuration));
|
|
5807
|
+
const totalHeightPx = slotsCount * SLOT_HEIGHT_PX;
|
|
5808
|
+
const resolvedMinEventDuration = minEventDuration ?? slotDuration;
|
|
5809
|
+
const hourMarks = useMemo10(() => {
|
|
5810
|
+
const marks = [];
|
|
5811
|
+
for (let hour = startHour; hour <= endHour; hour++) {
|
|
5812
|
+
const labelDate = new Date(2e3, 0, 1, hour === 24 ? 0 : hour, 0);
|
|
5813
|
+
marks.push({
|
|
5814
|
+
hour,
|
|
5815
|
+
label: hourFormatter.format(labelDate),
|
|
5816
|
+
top: (hour - startHour) * 60 / totalMinutes * 100
|
|
5817
|
+
});
|
|
5818
|
+
}
|
|
5819
|
+
return marks;
|
|
5820
|
+
}, [startHour, endHour, totalMinutes, hourFormatter]);
|
|
5821
|
+
const nowMinutes = now.getHours() * 60 + now.getMinutes();
|
|
5822
|
+
const showNowLine = nowMinutes >= startHour * 60 && nowMinutes < endHour * 60;
|
|
5823
|
+
const nowTop = (nowMinutes - startHour * 60) / totalMinutes * 100;
|
|
5824
|
+
const allDayEventsByDay = useMemo10(
|
|
5825
|
+
() => days.map(
|
|
5826
|
+
(day) => events.filter((event) => event.allDay && isSameDay(event.start, day))
|
|
5827
|
+
),
|
|
5828
|
+
[days, events]
|
|
5829
|
+
);
|
|
5830
|
+
const timedEventsByDay = useMemo10(
|
|
5831
|
+
() => days.map((day) => {
|
|
5832
|
+
const dayEvents = events.filter(
|
|
5833
|
+
(event) => !event.allDay && isSameDay(event.start, day)
|
|
5834
|
+
);
|
|
5835
|
+
const layout = layoutOverlappingEvents(
|
|
5836
|
+
dayEvents.map((event) => ({
|
|
5837
|
+
id: event.id,
|
|
5838
|
+
start: event.start,
|
|
5839
|
+
end: event.end
|
|
5840
|
+
}))
|
|
5841
|
+
);
|
|
5842
|
+
const layoutById = new Map(layout.map((l) => [l.id, l]));
|
|
5843
|
+
return dayEvents.map((event) => {
|
|
5844
|
+
const metrics = getVerticalMetrics(
|
|
5845
|
+
event.start,
|
|
5846
|
+
event.end,
|
|
5847
|
+
startHour,
|
|
5848
|
+
endHour
|
|
5849
|
+
);
|
|
5850
|
+
if (!metrics) return null;
|
|
5851
|
+
const placement = layoutById.get(event.id);
|
|
5852
|
+
return { event, metrics, placement };
|
|
5853
|
+
}).filter(
|
|
5854
|
+
(entry) => entry !== null
|
|
5855
|
+
);
|
|
5856
|
+
}),
|
|
5857
|
+
[days, events, startHour, endHour]
|
|
5858
|
+
);
|
|
5859
|
+
const [drag, setDrag] = useState21(null);
|
|
5860
|
+
const [announcement, setAnnouncement] = useState21("");
|
|
5861
|
+
const suppressClickRef = useRef12(false);
|
|
5862
|
+
const dayColumnRefs = useRef12([]);
|
|
5863
|
+
const announceMove = (event, start, end) => {
|
|
5864
|
+
setAnnouncement(
|
|
5865
|
+
`${event.title} moved to ${weekdayLongFormatter.format(start)}, ${formatEventTime(start, locale)} to ${formatEventTime(end, locale)}.`
|
|
5866
|
+
);
|
|
5867
|
+
};
|
|
5868
|
+
const announceResize = (event, end) => {
|
|
5869
|
+
setAnnouncement(
|
|
5870
|
+
`${event.title} resized to end at ${formatEventTime(end, locale)}.`
|
|
5871
|
+
);
|
|
5872
|
+
};
|
|
5873
|
+
const handleEventActivate = (event) => {
|
|
5874
|
+
if (suppressClickRef.current) {
|
|
5875
|
+
suppressClickRef.current = false;
|
|
5876
|
+
return;
|
|
5877
|
+
}
|
|
5878
|
+
onEventClick?.(event);
|
|
5879
|
+
};
|
|
5880
|
+
const handleMovePointerDown = (event, dayIndex) => (pointerEvent) => {
|
|
5881
|
+
if (!editable) return;
|
|
5882
|
+
pointerEvent.preventDefault();
|
|
5883
|
+
const target = pointerEvent.currentTarget;
|
|
5884
|
+
try {
|
|
5885
|
+
target.setPointerCapture(pointerEvent.pointerId);
|
|
5886
|
+
} catch {
|
|
5887
|
+
}
|
|
5888
|
+
target.focus();
|
|
5889
|
+
setDrag({
|
|
5890
|
+
kind: "move",
|
|
5891
|
+
event,
|
|
5892
|
+
pointerId: pointerEvent.pointerId,
|
|
5893
|
+
startClientX: pointerEvent.clientX,
|
|
5894
|
+
startClientY: pointerEvent.clientY,
|
|
5895
|
+
startDayIndex: dayIndex,
|
|
5896
|
+
currentDayIndex: dayIndex,
|
|
5897
|
+
currentStart: event.start,
|
|
5898
|
+
currentEnd: event.end,
|
|
5899
|
+
moved: false
|
|
5900
|
+
});
|
|
5901
|
+
};
|
|
5902
|
+
const handleResizePointerDown = (event, dayIndex) => (pointerEvent) => {
|
|
5903
|
+
if (!editable) return;
|
|
5904
|
+
pointerEvent.preventDefault();
|
|
5905
|
+
pointerEvent.stopPropagation();
|
|
5906
|
+
const target = pointerEvent.currentTarget;
|
|
5907
|
+
try {
|
|
5908
|
+
target.setPointerCapture(pointerEvent.pointerId);
|
|
5909
|
+
} catch {
|
|
5910
|
+
}
|
|
5911
|
+
setDrag({
|
|
5912
|
+
kind: "resize",
|
|
5913
|
+
event,
|
|
5914
|
+
pointerId: pointerEvent.pointerId,
|
|
5915
|
+
startClientX: pointerEvent.clientX,
|
|
5916
|
+
startClientY: pointerEvent.clientY,
|
|
5917
|
+
startDayIndex: dayIndex,
|
|
5918
|
+
currentDayIndex: dayIndex,
|
|
5919
|
+
currentStart: event.start,
|
|
5920
|
+
currentEnd: event.end,
|
|
5921
|
+
moved: false
|
|
5922
|
+
});
|
|
5923
|
+
};
|
|
5924
|
+
const handleDragPointerMove = (pointerEvent) => {
|
|
5925
|
+
if (!drag || pointerEvent.pointerId !== drag.pointerId) return;
|
|
5926
|
+
pointerEvent.stopPropagation();
|
|
5927
|
+
const deltaY = pointerEvent.clientY - drag.startClientY;
|
|
5928
|
+
if (drag.kind === "move") {
|
|
5929
|
+
const deltaX = pointerEvent.clientX - drag.startClientX;
|
|
5930
|
+
const columnWidth = dayColumnRefs.current[drag.startDayIndex]?.getBoundingClientRect().width ?? 0;
|
|
5931
|
+
const dayDelta = columnWidth > 0 ? Math.round(deltaX / columnWidth) : 0;
|
|
5932
|
+
const targetDayIndex = Math.min(6, Math.max(0, drag.startDayIndex + dayDelta));
|
|
5933
|
+
const targetDay = days[targetDayIndex];
|
|
5934
|
+
const { start, end } = computeMoveResult({
|
|
5935
|
+
originalStart: drag.event.start,
|
|
5936
|
+
originalEnd: drag.event.end,
|
|
5937
|
+
targetDay,
|
|
5938
|
+
deltaYPx: deltaY,
|
|
5939
|
+
slotDuration,
|
|
5940
|
+
startHour,
|
|
5941
|
+
endHour
|
|
5942
|
+
});
|
|
5943
|
+
const moved = targetDayIndex !== drag.startDayIndex || start.getTime() !== drag.event.start.getTime();
|
|
5944
|
+
setDrag({ ...drag, currentDayIndex: targetDayIndex, currentStart: start, currentEnd: end, moved });
|
|
5945
|
+
} else {
|
|
5946
|
+
const { end } = computeResizeResult({
|
|
5947
|
+
originalStart: drag.event.start,
|
|
5948
|
+
originalEnd: drag.event.end,
|
|
5949
|
+
deltaYPx: deltaY,
|
|
5950
|
+
slotDuration,
|
|
5951
|
+
minEventDuration: resolvedMinEventDuration,
|
|
5952
|
+
endHour
|
|
5953
|
+
});
|
|
5954
|
+
const moved = end.getTime() !== drag.event.end.getTime();
|
|
5955
|
+
setDrag({ ...drag, currentEnd: end, moved });
|
|
5956
|
+
}
|
|
5957
|
+
};
|
|
5958
|
+
const handleDragPointerUp = (pointerEvent) => {
|
|
5959
|
+
if (!drag || pointerEvent.pointerId !== drag.pointerId) return;
|
|
5960
|
+
pointerEvent.stopPropagation();
|
|
5961
|
+
const finished = drag;
|
|
5962
|
+
setDrag(null);
|
|
5963
|
+
if (finished.kind === "move") {
|
|
5964
|
+
if (!finished.moved) {
|
|
5965
|
+
suppressClickRef.current = true;
|
|
5966
|
+
onEventClick?.(finished.event);
|
|
5967
|
+
return;
|
|
5968
|
+
}
|
|
5969
|
+
onEventChange?.(finished.event, finished.currentStart, finished.currentEnd);
|
|
5970
|
+
announceMove(finished.event, finished.currentStart, finished.currentEnd);
|
|
5971
|
+
return;
|
|
5972
|
+
}
|
|
5973
|
+
if (!finished.moved) return;
|
|
5974
|
+
onEventChange?.(finished.event, finished.currentStart, finished.currentEnd);
|
|
5975
|
+
announceResize(finished.event, finished.currentEnd);
|
|
5976
|
+
};
|
|
5977
|
+
const handleDragPointerCancel = (pointerEvent) => {
|
|
5978
|
+
if (!drag || pointerEvent.pointerId !== drag.pointerId) return;
|
|
5979
|
+
pointerEvent.stopPropagation();
|
|
5980
|
+
setDrag(null);
|
|
5981
|
+
};
|
|
5982
|
+
const handleEventKeyDown = (keyboardEvent, event, dayIndex) => {
|
|
5983
|
+
if (!editable) return;
|
|
5984
|
+
if (keyboardEvent.shiftKey && (keyboardEvent.key === "ArrowDown" || keyboardEvent.key === "ArrowUp")) {
|
|
5985
|
+
keyboardEvent.preventDefault();
|
|
5986
|
+
const direction2 = keyboardEvent.key === "ArrowDown" ? 1 : -1;
|
|
5987
|
+
const { end } = computeResizeResult({
|
|
5988
|
+
originalStart: event.start,
|
|
5989
|
+
originalEnd: event.end,
|
|
5990
|
+
deltaYPx: direction2 * SLOT_HEIGHT_PX,
|
|
5991
|
+
slotDuration,
|
|
5992
|
+
minEventDuration: resolvedMinEventDuration,
|
|
5993
|
+
endHour
|
|
5994
|
+
});
|
|
5995
|
+
if (end.getTime() === event.end.getTime()) return;
|
|
5996
|
+
onEventChange?.(event, event.start, end);
|
|
5997
|
+
announceResize(event, end);
|
|
5998
|
+
return;
|
|
5999
|
+
}
|
|
6000
|
+
switch (keyboardEvent.key) {
|
|
6001
|
+
case "ArrowUp":
|
|
6002
|
+
case "ArrowDown": {
|
|
6003
|
+
keyboardEvent.preventDefault();
|
|
6004
|
+
const direction2 = keyboardEvent.key === "ArrowDown" ? 1 : -1;
|
|
6005
|
+
const { start, end } = computeMoveResult({
|
|
6006
|
+
originalStart: event.start,
|
|
6007
|
+
originalEnd: event.end,
|
|
6008
|
+
targetDay: days[dayIndex],
|
|
6009
|
+
deltaYPx: direction2 * SLOT_HEIGHT_PX,
|
|
6010
|
+
slotDuration,
|
|
6011
|
+
startHour,
|
|
6012
|
+
endHour
|
|
6013
|
+
});
|
|
6014
|
+
if (start.getTime() === event.start.getTime()) return;
|
|
6015
|
+
onEventChange?.(event, start, end);
|
|
6016
|
+
announceMove(event, start, end);
|
|
6017
|
+
break;
|
|
6018
|
+
}
|
|
6019
|
+
case "ArrowLeft":
|
|
6020
|
+
case "ArrowRight": {
|
|
6021
|
+
keyboardEvent.preventDefault();
|
|
6022
|
+
const direction2 = keyboardEvent.key === "ArrowRight" ? 1 : -1;
|
|
6023
|
+
const targetDayIndex = Math.min(6, Math.max(0, dayIndex + direction2));
|
|
6024
|
+
if (targetDayIndex === dayIndex) return;
|
|
6025
|
+
const { start, end } = computeMoveResult({
|
|
6026
|
+
originalStart: event.start,
|
|
6027
|
+
originalEnd: event.end,
|
|
6028
|
+
targetDay: days[targetDayIndex],
|
|
6029
|
+
deltaYPx: 0,
|
|
6030
|
+
slotDuration,
|
|
6031
|
+
startHour,
|
|
6032
|
+
endHour
|
|
6033
|
+
});
|
|
6034
|
+
onEventChange?.(event, start, end);
|
|
6035
|
+
announceMove(event, start, end);
|
|
6036
|
+
break;
|
|
6037
|
+
}
|
|
6038
|
+
default:
|
|
6039
|
+
return;
|
|
6040
|
+
}
|
|
6041
|
+
};
|
|
6042
|
+
const dragPreviewMetrics = drag && drag.kind === "move" ? getVerticalMetrics(drag.currentStart, drag.currentEnd, startHour, endHour) : null;
|
|
6043
|
+
return /* @__PURE__ */ jsxs34("div", { className: [root9, className].filter(Boolean).join(" "), children: [
|
|
6044
|
+
/* @__PURE__ */ jsx51(
|
|
6045
|
+
"div",
|
|
6046
|
+
{
|
|
6047
|
+
"aria-live": "polite",
|
|
6048
|
+
className: visuallyHidden,
|
|
6049
|
+
children: announcement
|
|
6050
|
+
}
|
|
6051
|
+
),
|
|
6052
|
+
/* @__PURE__ */ jsxs34("div", { className: header2, children: [
|
|
6053
|
+
/* @__PURE__ */ jsx51("span", { className: rangeLabel, children: rangeLabelText }),
|
|
6054
|
+
/* @__PURE__ */ jsxs34("div", { className: headerNav, children: [
|
|
6055
|
+
/* @__PURE__ */ jsx51(
|
|
6056
|
+
"button",
|
|
6057
|
+
{
|
|
6058
|
+
type: "button",
|
|
6059
|
+
className: navButton2,
|
|
6060
|
+
"aria-label": "Previous week",
|
|
6061
|
+
onClick: () => onDateChange?.(addDays(date, -7)),
|
|
6062
|
+
children: "\u2039"
|
|
6063
|
+
}
|
|
6064
|
+
),
|
|
6065
|
+
/* @__PURE__ */ jsx51(
|
|
6066
|
+
"button",
|
|
6067
|
+
{
|
|
6068
|
+
type: "button",
|
|
6069
|
+
className: todayButton,
|
|
6070
|
+
onClick: () => onDateChange?.(/* @__PURE__ */ new Date()),
|
|
6071
|
+
children: "Today"
|
|
6072
|
+
}
|
|
6073
|
+
),
|
|
6074
|
+
/* @__PURE__ */ jsx51(
|
|
6075
|
+
"button",
|
|
6076
|
+
{
|
|
6077
|
+
type: "button",
|
|
6078
|
+
className: navButton2,
|
|
6079
|
+
"aria-label": "Next week",
|
|
6080
|
+
onClick: () => onDateChange?.(addDays(date, 7)),
|
|
6081
|
+
children: "\u203A"
|
|
6082
|
+
}
|
|
6083
|
+
)
|
|
6084
|
+
] })
|
|
6085
|
+
] }),
|
|
6086
|
+
/* @__PURE__ */ jsxs34("div", { className: dayHeaderRow, children: [
|
|
6087
|
+
/* @__PURE__ */ jsx51("div", { className: dayHeaderGutter }),
|
|
6088
|
+
days.map((day) => {
|
|
6089
|
+
const isToday = isSameDay(day, today);
|
|
6090
|
+
return /* @__PURE__ */ jsxs34("div", { className: dayHeaderCell, "data-today": isToday || void 0, children: [
|
|
6091
|
+
/* @__PURE__ */ jsx51("span", { children: weekdayFormatter.format(day) }),
|
|
6092
|
+
/* @__PURE__ */ jsx51("span", { className: dayHeaderDateNumber, "data-today": isToday || void 0, children: dayNumberFormatter.format(day) })
|
|
6093
|
+
] }, day.toISOString());
|
|
6094
|
+
})
|
|
6095
|
+
] }),
|
|
6096
|
+
/* @__PURE__ */ jsxs34("div", { className: allDayRow, children: [
|
|
6097
|
+
/* @__PURE__ */ jsx51("div", { className: allDayGutter, children: "All day" }),
|
|
6098
|
+
days.map((day, dayIndex) => /* @__PURE__ */ jsx51("div", { className: allDayCell, children: allDayEventsByDay[dayIndex].map((event) => {
|
|
6099
|
+
const color = getEventColor(event.id, event.color);
|
|
6100
|
+
const selected = event.id === selectedEventId;
|
|
6101
|
+
return /* @__PURE__ */ jsx51(
|
|
6102
|
+
"button",
|
|
6103
|
+
{
|
|
6104
|
+
type: "button",
|
|
6105
|
+
className: allDayEventBlock,
|
|
6106
|
+
style: { background: color },
|
|
6107
|
+
"data-selected": selected || void 0,
|
|
6108
|
+
onClick: () => handleEventActivate(event),
|
|
6109
|
+
children: event.title
|
|
6110
|
+
},
|
|
6111
|
+
event.id
|
|
6112
|
+
);
|
|
6113
|
+
}) }, day.toISOString()))
|
|
6114
|
+
] }),
|
|
6115
|
+
/* @__PURE__ */ jsxs34("div", { className: scrollArea, children: [
|
|
6116
|
+
/* @__PURE__ */ jsx51("div", { className: timeGutter, style: { height: totalHeightPx }, children: hourMarks.map((mark) => /* @__PURE__ */ jsx51(
|
|
6117
|
+
"span",
|
|
6118
|
+
{
|
|
6119
|
+
className: hourLabel,
|
|
6120
|
+
style: { top: `${mark.top}%` },
|
|
6121
|
+
children: mark.label
|
|
6122
|
+
},
|
|
6123
|
+
mark.hour
|
|
6124
|
+
)) }),
|
|
6125
|
+
days.map((day, dayIndex) => {
|
|
6126
|
+
const isToday = isSameDay(day, today);
|
|
6127
|
+
return /* @__PURE__ */ jsxs34(
|
|
6128
|
+
"div",
|
|
6129
|
+
{
|
|
6130
|
+
ref: (el) => {
|
|
6131
|
+
dayColumnRefs.current[dayIndex] = el;
|
|
6132
|
+
},
|
|
6133
|
+
className: dayColumn,
|
|
6134
|
+
style: { height: totalHeightPx },
|
|
6135
|
+
children: [
|
|
6136
|
+
isToday && showNowLine ? /* @__PURE__ */ jsx51("div", { className: nowLine, style: { top: `${nowTop}%` }, children: /* @__PURE__ */ jsx51("span", { className: nowLineDot }) }) : null,
|
|
6137
|
+
timedEventsByDay[dayIndex].map(({ event, metrics, placement }) => {
|
|
6138
|
+
const color = getEventColor(event.id, event.color);
|
|
6139
|
+
const selected = event.id === selectedEventId;
|
|
6140
|
+
const isResizingThis = drag?.kind === "resize" && drag.event.id === event.id;
|
|
6141
|
+
const isDraggingThis = drag?.event.id === event.id;
|
|
6142
|
+
const displayMetrics = isResizingThis ? getVerticalMetrics(event.start, drag.currentEnd, startHour, endHour) ?? metrics : metrics;
|
|
6143
|
+
const displayEnd = isResizingThis ? drag.currentEnd : event.end;
|
|
6144
|
+
const width = 100 / placement.columnCount;
|
|
6145
|
+
const left = placement.columnIndex * width;
|
|
6146
|
+
const showTime = displayMetrics.height > 6;
|
|
6147
|
+
return /* @__PURE__ */ jsxs34(
|
|
6148
|
+
"button",
|
|
6149
|
+
{
|
|
6150
|
+
type: "button",
|
|
6151
|
+
className: eventBlock,
|
|
6152
|
+
"data-selected": selected || void 0,
|
|
6153
|
+
"data-editable": editable || void 0,
|
|
6154
|
+
"data-dragging": isDraggingThis || void 0,
|
|
6155
|
+
style: {
|
|
6156
|
+
top: `${displayMetrics.top}%`,
|
|
6157
|
+
height: `${displayMetrics.height}%`,
|
|
6158
|
+
left: `${left}%`,
|
|
6159
|
+
width: `${width}%`,
|
|
6160
|
+
background: color
|
|
6161
|
+
},
|
|
6162
|
+
onClick: () => handleEventActivate(event),
|
|
6163
|
+
onPointerDown: editable ? handleMovePointerDown(event, dayIndex) : void 0,
|
|
6164
|
+
onPointerMove: editable ? handleDragPointerMove : void 0,
|
|
6165
|
+
onPointerUp: editable ? handleDragPointerUp : void 0,
|
|
6166
|
+
onPointerCancel: editable ? handleDragPointerCancel : void 0,
|
|
6167
|
+
onKeyDown: editable ? (e) => handleEventKeyDown(e, event, dayIndex) : void 0,
|
|
6168
|
+
children: [
|
|
6169
|
+
/* @__PURE__ */ jsx51("span", { className: eventTitle, children: event.title }),
|
|
6170
|
+
showTime ? /* @__PURE__ */ jsxs34("span", { className: eventTime, children: [
|
|
6171
|
+
formatEventTime(event.start, locale),
|
|
6172
|
+
" \u2013",
|
|
6173
|
+
" ",
|
|
6174
|
+
formatEventTime(displayEnd, locale)
|
|
6175
|
+
] }) : null,
|
|
6176
|
+
editable ? /* @__PURE__ */ jsx51(
|
|
6177
|
+
"span",
|
|
6178
|
+
{
|
|
6179
|
+
className: resizeHandle2,
|
|
6180
|
+
onPointerDown: handleResizePointerDown(event, dayIndex),
|
|
6181
|
+
onPointerMove: handleDragPointerMove,
|
|
6182
|
+
onPointerUp: handleDragPointerUp,
|
|
6183
|
+
onPointerCancel: handleDragPointerCancel
|
|
6184
|
+
}
|
|
6185
|
+
) : null
|
|
6186
|
+
]
|
|
6187
|
+
},
|
|
6188
|
+
event.id
|
|
6189
|
+
);
|
|
6190
|
+
}),
|
|
6191
|
+
drag && drag.kind === "move" && drag.currentDayIndex === dayIndex && dragPreviewMetrics ? /* @__PURE__ */ jsxs34(
|
|
6192
|
+
"div",
|
|
6193
|
+
{
|
|
6194
|
+
className: dragPreview,
|
|
6195
|
+
style: {
|
|
6196
|
+
top: `${dragPreviewMetrics.top}%`,
|
|
6197
|
+
height: `${dragPreviewMetrics.height}%`,
|
|
6198
|
+
left: 0,
|
|
6199
|
+
width: "100%"
|
|
6200
|
+
},
|
|
6201
|
+
children: [
|
|
6202
|
+
/* @__PURE__ */ jsx51("span", { className: dragPreviewLabel, children: drag.event.title }),
|
|
6203
|
+
/* @__PURE__ */ jsxs34("span", { className: dragPreviewLabel, children: [
|
|
6204
|
+
formatEventTime(drag.currentStart, locale),
|
|
6205
|
+
" \u2013",
|
|
6206
|
+
" ",
|
|
6207
|
+
formatEventTime(drag.currentEnd, locale)
|
|
6208
|
+
] })
|
|
6209
|
+
]
|
|
6210
|
+
}
|
|
6211
|
+
) : null
|
|
6212
|
+
]
|
|
6213
|
+
},
|
|
6214
|
+
day.toISOString()
|
|
6215
|
+
);
|
|
6216
|
+
})
|
|
6217
|
+
] })
|
|
6218
|
+
] });
|
|
6219
|
+
}
|
|
6220
|
+
|
|
5588
6221
|
// src/index.ts
|
|
5589
|
-
import { vars as
|
|
6222
|
+
import { vars as vars13, defaultThemeClass, defaultThemeVars } from "@vesture/tokens";
|
|
5590
6223
|
export {
|
|
5591
6224
|
Accordion2 as Accordion,
|
|
5592
6225
|
AccordionContent,
|
|
@@ -5625,6 +6258,7 @@ export {
|
|
|
5625
6258
|
Popover,
|
|
5626
6259
|
Progress,
|
|
5627
6260
|
Radio,
|
|
6261
|
+
Scheduler,
|
|
5628
6262
|
Select,
|
|
5629
6263
|
Slider,
|
|
5630
6264
|
Spinner,
|
|
@@ -5642,6 +6276,6 @@ export {
|
|
|
5642
6276
|
defaultThemeVars,
|
|
5643
6277
|
useCommandPaletteShortcut,
|
|
5644
6278
|
useToast,
|
|
5645
|
-
|
|
6279
|
+
vars13 as vars
|
|
5646
6280
|
};
|
|
5647
6281
|
//# sourceMappingURL=index.js.map
|