@weekwise/react 0.3.1 → 0.4.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/README.md +69 -9
- package/dist/Calendar.d.ts +4 -3
- package/dist/Calendar.js +20 -0
- package/dist/Calendar.js.map +1 -0
- package/dist/Calendar.module.css.js +11 -0
- package/dist/Calendar.module.css.js.map +1 -0
- package/dist/Calendar.types.d.ts +34 -6
- package/dist/CalendarBase.d.ts +8 -0
- package/dist/CalendarBase.js +161 -0
- package/dist/CalendarBase.js.map +1 -0
- package/dist/components/calendar-toolbar/CalendarToolbar.js +51 -0
- package/dist/components/calendar-toolbar/CalendarToolbar.js.map +1 -0
- package/dist/components/calendar-toolbar/CalendarToolbar.module.css.js +15 -0
- package/dist/components/calendar-toolbar/CalendarToolbar.module.css.js.map +1 -0
- package/dist/components/date-navigator/DateNavigator.js +129 -0
- package/dist/components/date-navigator/DateNavigator.js.map +1 -0
- package/dist/components/date-navigator/DateNavigator.module.css.js +25 -0
- package/dist/components/date-navigator/DateNavigator.module.css.js.map +1 -0
- package/dist/components/day-week-drawer/DayWeekDrawer.js +227 -0
- package/dist/components/day-week-drawer/DayWeekDrawer.js.map +1 -0
- package/dist/components/day-week-drawer/DayWeekDrawer.module.css.js +15 -0
- package/dist/components/day-week-drawer/DayWeekDrawer.module.css.js.map +1 -0
- package/dist/components/day-week-event/DayWeekEvent.js +154 -0
- package/dist/components/day-week-event/DayWeekEvent.js.map +1 -0
- package/dist/components/day-week-event/DayWeekEvent.module.css.js +17 -0
- package/dist/components/day-week-event/DayWeekEvent.module.css.js.map +1 -0
- package/dist/components/day-week-event/DayWeekEventPreview.js +26 -0
- package/dist/components/day-week-event/DayWeekEventPreview.js.map +1 -0
- package/dist/components/day-week-view/DayWeekView.js +226 -0
- package/dist/components/day-week-view/DayWeekView.js.map +1 -0
- package/dist/components/day-week-view/DayWeekView.module.css.js +27 -0
- package/dist/components/day-week-view/DayWeekView.module.css.js.map +1 -0
- package/dist/components/day-week-view/HiddenEvents.js +78 -0
- package/dist/components/day-week-view/HiddenEvents.js.map +1 -0
- package/dist/components/day-week-view/useTimeColumnWidth.js +34 -0
- package/dist/components/day-week-view/useTimeColumnWidth.js.map +1 -0
- package/dist/components/drag-overlay/DragOverlay.js +98 -0
- package/dist/components/drag-overlay/DragOverlay.js.map +1 -0
- package/dist/components/drag-overlay/DragOverlay.module.css.js +12 -0
- package/dist/components/drag-overlay/DragOverlay.module.css.js.map +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/month-view/MonthView.d.ts +8 -2
- package/dist/components/month-view/MonthView.js +105 -0
- package/dist/components/month-view/MonthView.js.map +1 -0
- package/dist/components/month-view/MonthView.module.css.js +30 -0
- package/dist/components/month-view/MonthView.module.css.js.map +1 -0
- package/dist/components/month-view/MonthView.utils.js +14 -0
- package/dist/components/month-view/MonthView.utils.js.map +1 -0
- package/dist/components/month-view/MonthViewDay.d.ts +2 -0
- package/dist/components/month-view/MonthViewDay.js +75 -0
- package/dist/components/month-view/MonthViewDay.js.map +1 -0
- package/dist/components/month-view/MonthViewEvent.js +132 -0
- package/dist/components/month-view/MonthViewEvent.js.map +1 -0
- package/dist/components/month-view/MonthViewEventPreview.js +28 -0
- package/dist/components/month-view/MonthViewEventPreview.js.map +1 -0
- package/dist/components/month-view/MonthViewWeek.d.ts +5 -0
- package/dist/components/month-view/MonthViewWeek.js +67 -0
- package/dist/components/month-view/MonthViewWeek.js.map +1 -0
- package/dist/components/month-view/useMonthLanes.js +22 -0
- package/dist/components/month-view/useMonthLanes.js.map +1 -0
- package/dist/components/month-view/useMonthResize.js +57 -0
- package/dist/components/month-view/useMonthResize.js.map +1 -0
- package/dist/components/nav-btn/NavBtn.js +28 -0
- package/dist/components/nav-btn/NavBtn.js.map +1 -0
- package/dist/components/nav-btn/NavBtn.module.css.js +11 -0
- package/dist/components/nav-btn/NavBtn.module.css.js.map +1 -0
- package/dist/components/pointer-popover/PointerPopover.js +22 -0
- package/dist/components/pointer-popover/PointerPopover.js.map +1 -0
- package/dist/components/pointer-popover/PointerPopover.module.css.js +6 -0
- package/dist/components/pointer-popover/PointerPopover.module.css.js.map +1 -0
- package/dist/components/timeline-view/TimelineView.d.ts +6 -0
- package/dist/components/timeline-view/TimelineView.js +10 -0
- package/dist/components/timeline-view/TimelineView.js.map +1 -0
- package/dist/components/timeline-view/index.d.ts +1 -0
- package/dist/components/view-select/ViewSelect.d.ts +1 -1
- package/dist/components/view-select/ViewSelect.js +117 -0
- package/dist/components/view-select/ViewSelect.js.map +1 -0
- package/dist/components/view-select/ViewSelect.module.css.js +14 -0
- package/dist/components/view-select/ViewSelect.module.css.js.map +1 -0
- package/dist/contexts/CalendarContext.js +14 -0
- package/dist/contexts/CalendarContext.js.map +1 -0
- package/dist/contexts/CalendarViewportContext.js +14 -0
- package/dist/contexts/CalendarViewportContext.js.map +1 -0
- package/dist/contexts/DayWeekDrawerContext.js +14 -0
- package/dist/contexts/DayWeekDrawerContext.js.map +1 -0
- package/dist/contexts/DayWeekViewContext.js +14 -0
- package/dist/contexts/DayWeekViewContext.js.map +1 -0
- package/dist/contexts/ThemeSourceContext.js +9 -0
- package/dist/contexts/ThemeSourceContext.js.map +1 -0
- package/dist/date-localization/DateLocalizationContext.js +9 -0
- package/dist/date-localization/DateLocalizationContext.js.map +1 -0
- package/dist/date-localization/DateLocalizationProvider.js +20 -0
- package/dist/date-localization/DateLocalizationProvider.js.map +1 -0
- package/dist/date-localization/MessagesContext.js +9 -0
- package/dist/date-localization/MessagesContext.js.map +1 -0
- package/dist/date-localization/useDateUtils.js +15 -0
- package/dist/date-localization/useDateUtils.js.map +1 -0
- package/dist/date-localization/useMessages.js +13 -0
- package/dist/date-localization/useMessages.js.map +1 -0
- package/dist/hooks/useAbsEventRect.js +27 -0
- package/dist/hooks/useAbsEventRect.js.map +1 -0
- package/dist/hooks/useAutoScroller.js +83 -0
- package/dist/hooks/useAutoScroller.js.map +1 -0
- package/dist/hooks/useCalendarSize.js +20 -0
- package/dist/hooks/useCalendarSize.js.map +1 -0
- package/dist/hooks/useCalendarValue.d.ts +1 -1
- package/dist/hooks/useCalendarValue.js +51 -0
- package/dist/hooks/useCalendarValue.js.map +1 -0
- package/dist/hooks/useCanResizeEvent.js +29 -0
- package/dist/hooks/useCanResizeEvent.js.map +1 -0
- package/dist/hooks/useComputed.js +14 -0
- package/dist/hooks/useComputed.js.map +1 -0
- package/dist/hooks/useControlled.js +20 -0
- package/dist/hooks/useControlled.js.map +1 -0
- package/dist/hooks/useControlled.utils.js +33 -0
- package/dist/hooks/useControlled.utils.js.map +1 -0
- package/dist/hooks/useCurrentRef.js +10 -0
- package/dist/hooks/useCurrentRef.js.map +1 -0
- package/dist/hooks/useDocumentCursor.js +13 -0
- package/dist/hooks/useDocumentCursor.js.map +1 -0
- package/dist/hooks/useEventCallback.js +12 -0
- package/dist/hooks/useEventCallback.js.map +1 -0
- package/dist/hooks/useEventCallback.utils.js +20 -0
- package/dist/hooks/useEventCallback.utils.js.map +1 -0
- package/dist/hooks/useEventResize.js +106 -0
- package/dist/hooks/useEventResize.js.map +1 -0
- package/dist/hooks/useGlobalListeners.js +40 -0
- package/dist/hooks/useGlobalListeners.js.map +1 -0
- package/dist/hooks/useInterval.js +14 -0
- package/dist/hooks/useInterval.js.map +1 -0
- package/dist/hooks/useIsomorphicLayoutEffect.js +6 -0
- package/dist/hooks/useIsomorphicLayoutEffect.js.map +1 -0
- package/dist/hooks/useItemsLayout.js +53 -0
- package/dist/hooks/useItemsLayout.js.map +1 -0
- package/dist/hooks/useMergedRefs.js +10 -0
- package/dist/hooks/useMergedRefs.js.map +1 -0
- package/dist/hooks/useMove.js +180 -0
- package/dist/hooks/useMove.js.map +1 -0
- package/dist/hooks/useMoveTransform.js +118 -0
- package/dist/hooks/useMoveTransform.js.map +1 -0
- package/dist/hooks/useMutationObserver.js +16 -0
- package/dist/hooks/useMutationObserver.js.map +1 -0
- package/dist/hooks/useNavigation.js +15 -0
- package/dist/hooks/useNavigation.js.map +1 -0
- package/dist/hooks/usePrevious.js +12 -0
- package/dist/hooks/usePrevious.js.map +1 -0
- package/dist/hooks/useRect.js +37 -0
- package/dist/hooks/useRect.js.map +1 -0
- package/dist/hooks/useRefList.js +21 -0
- package/dist/hooks/useRefList.js.map +1 -0
- package/dist/hooks/useRefWithInit.js +11 -0
- package/dist/hooks/useRefWithInit.js.map +1 -0
- package/dist/hooks/useResizeObserver.js +16 -0
- package/dist/hooks/useResizeObserver.js.map +1 -0
- package/dist/hooks/useScrollBarSize.js +37 -0
- package/dist/hooks/useScrollBarSize.js.map +1 -0
- package/dist/hooks/useScrollIntent.js +41 -0
- package/dist/hooks/useScrollIntent.js.map +1 -0
- package/dist/hooks/useScrollOffsets.js +33 -0
- package/dist/hooks/useScrollOffsets.js.map +1 -0
- package/dist/hooks/useScrollOffsetsDelta.js +16 -0
- package/dist/hooks/useScrollOffsetsDelta.js.map +1 -0
- package/dist/hooks/useScrollableAncestors.js +14 -0
- package/dist/hooks/useScrollableAncestors.js.map +1 -0
- package/dist/hooks/useScrollableAncestorsRects.js +32 -0
- package/dist/hooks/useScrollableAncestorsRects.js.map +1 -0
- package/dist/hooks/useStateRef.js +16 -0
- package/dist/hooks/useStateRef.js.map +1 -0
- package/dist/hooks/useTimeInterval.js +25 -0
- package/dist/hooks/useTimeInterval.js.map +1 -0
- package/dist/hooks/useTimeOffset.js +24 -0
- package/dist/hooks/useTimeOffset.js.map +1 -0
- package/dist/hooks/useToday.js +26 -0
- package/dist/hooks/useToday.js.map +1 -0
- package/dist/icons/chevron.js +20 -0
- package/dist/icons/chevron.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +12 -2798
- package/dist/portal/Portal.js +31 -0
- package/dist/portal/Portal.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/utils/mergeRefs.js +15 -0
- package/dist/utils/mergeRefs.js.map +1 -0
- package/dist/views/dayView.d.ts +4 -0
- package/dist/views/dayView.js +13 -0
- package/dist/views/dayView.js.map +1 -0
- package/dist/views/index.d.ts +4 -0
- package/dist/views/monthView.d.ts +9 -0
- package/dist/views/monthView.js +20 -0
- package/dist/views/monthView.js.map +1 -0
- package/dist/views/types.d.ts +30 -0
- package/dist/views/weekView.d.ts +4 -0
- package/dist/views/weekView.js +13 -0
- package/dist/views/weekView.js.map +1 -0
- package/package.json +7 -7
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMessages.js","names":["useContext","resolveMessages","MessagesContext","useDateUtils","useMessages","messages","dateUtils"],"sources":["../../src/date-localization/useMessages.ts"],"sourcesContent":["import { useContext } from \"react\";\n\nimport { resolveMessages } from \"@weekwise/core\";\n\nimport MessagesContext from \"./MessagesContext\";\nimport useDateUtils from \"./useDateUtils\";\n\n/** Interface strings in the language of the date adapter's locale. */\nexport default function useMessages() {\n const messages = useContext(MessagesContext);\n const dateUtils = useDateUtils();\n return messages ?? resolveMessages(dateUtils.locale);\n}\n"],"mappings":";;;;;;AAQA,SAAwBI,IAAc;CACpC,IAAMC,IAAWL,EAAWE,CAAe,GACrCI,IAAYH,EAAa;CAC/B,OAAOE,KAAYJ,EAAgBK,EAAU,MAAM;AACrD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState as e } from "react";
|
|
3
|
+
import t from "./useIsomorphicLayoutEffect.js";
|
|
4
|
+
import { getClientRect as n, round as r, subtract as i } from "@weekwise/core";
|
|
5
|
+
// src/hooks/useAbsEventRect.ts
|
|
6
|
+
function a(a, o, s) {
|
|
7
|
+
let [c, l] = e(null);
|
|
8
|
+
return t(() => {
|
|
9
|
+
let e = a.current, t = o.current;
|
|
10
|
+
if (e && t) {
|
|
11
|
+
let { height: a, width: o, ...c } = n(e), { left: u, top: d } = i(c, n(t));
|
|
12
|
+
l(r(s, {
|
|
13
|
+
height: a,
|
|
14
|
+
width: o,
|
|
15
|
+
x: u,
|
|
16
|
+
y: d
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
}, [
|
|
20
|
+
a,
|
|
21
|
+
o,
|
|
22
|
+
...Object.values(s)
|
|
23
|
+
]), c;
|
|
24
|
+
}
|
|
25
|
+
export { a as default };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=useAbsEventRect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAbsEventRect.js","names":["useState","useIsomorphicLayoutEffect","getClientRect","round","subtract","useAbsEventRect","rootRef","containerRef","relativeRect","absEventRect","setAbsEventRect","rootEl","parentEl","height","width","positions","x","y"],"sources":["../../src/hooks/useAbsEventRect.ts"],"sourcesContent":["import { useState, type RefObject } from \"react\";\n\nimport type { MeasuredEventData } from \"../components/day-week-view\";\nimport { useIsomorphicLayoutEffect } from \"../hooks\";\nimport { getClientRect, round, subtract } from \"@weekwise/core\";\n\nexport default function useAbsEventRect(\n rootRef: RefObject<HTMLDivElement | null>,\n /** The element the event is positioned in. */\n containerRef: RefObject<HTMLElement | null>,\n relativeRect: MeasuredEventData[\"rect\"]\n) {\n const [absEventRect, setAbsEventRect] = useState<MeasuredEventData[\"rect\"] | null>(null);\n\n useIsomorphicLayoutEffect(() => {\n const rootEl = rootRef.current,\n parentEl = containerRef.current;\n\n if (rootEl && parentEl) {\n const { height, width, ...positions } = getClientRect(rootEl);\n const { left: x, top: y } = subtract(positions, getClientRect(parentEl));\n\n setAbsEventRect(\n // sometimes the values can be floating, so we need to round them\n round(relativeRect, { height, width, x, y })\n );\n }\n // oxlint-disable-next-line react-hooks/exhaustive-deps\n }, [rootRef, containerRef, ...Object.values(relativeRect)]);\n\n return absEventRect;\n}\n"],"mappings":";;;;;AAMA,SAAwBK,EACtBC,GAEAC,GACAC,GACA;CACA,IAAM,CAACC,GAAcC,KAAmBV,EAA2C,IAAI;CAkBvF,OAhBAC,QAAgC;EAC9B,IAAMU,IAASL,EAAQ,SACrBM,IAAWL,EAAa;EAE1B,IAAII,KAAUC,GAAU;GACtB,IAAM,EAAEC,WAAQC,UAAO,GAAGC,MAAcb,EAAcS,CAAM,GACtD,EAAE,MAAMK,GAAG,KAAKC,MAAMb,EAASW,GAAWb,EAAcU,CAAQ,CAAC;GAEvEF,EAEEP,EAAMK,GAAc;IAAEK;IAAQC;IAAOE;IAAGC;GAAE,CAAC,CAC7C;EACF;CAEF,GAAG;EAACX;EAASC;EAAc,GAAG,OAAO,OAAOC,CAAY;CAAC,CAAC,GAEnDC;AACT"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback as e, useEffect as t, useMemo as n, useRef as r } from "react";
|
|
3
|
+
import { getScrollDirectionAndSpeed as i } from "@weekwise/core";
|
|
4
|
+
import { useInterval as a } from "./useInterval.js";
|
|
5
|
+
import o from "./useScrollIntent.js";
|
|
6
|
+
// src/hooks/useAutoScroller.ts
|
|
7
|
+
function s(s) {
|
|
8
|
+
let { acceleration: c, activator: l = 0, canScroll: u, enabled: d, interval: f = 5, pointerCoordinates: p, order: m = 0, delta: h, threshold: g, activeNodeRect: _, scrollableAncestors: v, scrollableAncestorsRects: y } = s, [b, x] = a(), S = o({
|
|
9
|
+
delta: h,
|
|
10
|
+
disabled: !d
|
|
11
|
+
}), C = r({
|
|
12
|
+
x: 0,
|
|
13
|
+
y: 0
|
|
14
|
+
}), w = r({
|
|
15
|
+
x: 0,
|
|
16
|
+
y: 0
|
|
17
|
+
}), T = r(null), E = n(() => m === 0 ? [[...v].reverse(), [...y].reverse()] : [[...v], [...y]], [
|
|
18
|
+
m,
|
|
19
|
+
v,
|
|
20
|
+
y
|
|
21
|
+
]), D = n(() => {
|
|
22
|
+
switch (l) {
|
|
23
|
+
case 0: return p ? {
|
|
24
|
+
top: p.y,
|
|
25
|
+
bottom: p.y,
|
|
26
|
+
left: p.x,
|
|
27
|
+
right: p.x
|
|
28
|
+
} : null;
|
|
29
|
+
case 1: return _;
|
|
30
|
+
}
|
|
31
|
+
}, [
|
|
32
|
+
l,
|
|
33
|
+
_,
|
|
34
|
+
p
|
|
35
|
+
]), O = e(() => {
|
|
36
|
+
let e = T.current;
|
|
37
|
+
if (!e) return;
|
|
38
|
+
let t = C.current.x * w.current.x, n = C.current.y * w.current.y;
|
|
39
|
+
e.scrollBy(t, n);
|
|
40
|
+
}, []);
|
|
41
|
+
t(() => {
|
|
42
|
+
let [e, t] = E;
|
|
43
|
+
if (!d || !e.length || !D) x();
|
|
44
|
+
else {
|
|
45
|
+
for (let [n, r] of e.entries()) {
|
|
46
|
+
if (!r || u?.(r) === !1) continue;
|
|
47
|
+
let e = t[n];
|
|
48
|
+
if (!e) continue;
|
|
49
|
+
let { direction: a, speed: o } = i(r, e, D, c, g);
|
|
50
|
+
for (let e of ["x", "y"]) S[e][a[e]] || (o[e] = 0, a[e] = 0);
|
|
51
|
+
if (o.x > 0 || o.y > 0) {
|
|
52
|
+
x(), b(O, f), T.current = r, C.current = o, w.current = a;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
C.current = {
|
|
57
|
+
x: 0,
|
|
58
|
+
y: 0
|
|
59
|
+
}, w.current = {
|
|
60
|
+
x: 0,
|
|
61
|
+
y: 0
|
|
62
|
+
}, x();
|
|
63
|
+
}
|
|
64
|
+
}, [
|
|
65
|
+
c,
|
|
66
|
+
O,
|
|
67
|
+
u,
|
|
68
|
+
d,
|
|
69
|
+
f,
|
|
70
|
+
D,
|
|
71
|
+
v,
|
|
72
|
+
E,
|
|
73
|
+
g,
|
|
74
|
+
x,
|
|
75
|
+
b,
|
|
76
|
+
...Object.entries(D || {}),
|
|
77
|
+
...Object.entries(S),
|
|
78
|
+
...Object.entries(g || {})
|
|
79
|
+
]);
|
|
80
|
+
}
|
|
81
|
+
export { s as useAutoScroller };
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=useAutoScroller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAutoScroller.js","names":["useCallback","useEffect","useMemo","useRef","getScrollDirectionAndSpeed","useInterval","useScrollIntent","useAutoScroller","args","acceleration","activator","canScroll","enabled","interval","pointerCoordinates","order","delta","threshold","activeNodeRect","scrollableAncestors","scrollableAncestorsRects","setAutoScrollInterval","clearAutoScrollInterval","scrollIntent","scrollSpeed","scrollDirection","scrollContainerRef","sortedScrollableAncestorsWithRects","rect","autoScroll","scrollContainer","scrollLeft","scrollTop","index","scrollContainerRect","direction","speed","axis"],"sources":["../../src/hooks/useAutoScroller.ts"],"sourcesContent":["/* oxlint-disable react-hooks/exhaustive-deps */\nimport { useCallback, useEffect, useMemo, useRef } from \"react\";\n\nimport type { ClientRect, Coordinates } from \"@weekwise/core\";\n\nimport { getScrollDirectionAndSpeed } from \"@weekwise/core\";\nimport { useInterval } from \"./useInterval\";\nimport useScrollIntent, { type ScrollDirection as Direction } from \"./useScrollIntent\";\n\nenum AutoScrollActivator {\n Pointer,\n DraggableRect,\n}\n\nenum TraversalOrder {\n TreeOrder,\n ReversedTreeOrder,\n}\n\nexport function useAutoScroller(args: UseAutoScrollerParams) {\n const {\n acceleration,\n activator = AutoScrollActivator.Pointer,\n canScroll,\n enabled,\n interval = 5,\n pointerCoordinates,\n order = TraversalOrder.TreeOrder,\n delta,\n threshold,\n activeNodeRect,\n scrollableAncestors,\n scrollableAncestorsRects,\n } = args;\n\n const [setAutoScrollInterval, clearAutoScrollInterval] = useInterval();\n\n const scrollIntent = useScrollIntent({ delta, disabled: !enabled });\n const scrollSpeed = useRef<Coordinates>({ x: 0, y: 0 });\n const scrollDirection = useRef<ScrollDirection>({ x: 0, y: 0 });\n const scrollContainerRef = useRef<Element | null>(null);\n const sortedScrollableAncestorsWithRects = useMemo<[Element[], ClientRect[]]>(\n () =>\n order === TraversalOrder.TreeOrder\n ? [[...scrollableAncestors].reverse(), [...scrollableAncestorsRects].reverse()]\n : [[...scrollableAncestors], [...scrollableAncestorsRects]],\n [order, scrollableAncestors, scrollableAncestorsRects]\n );\n\n const rect = useMemo(() => {\n switch (activator) {\n case AutoScrollActivator.Pointer:\n return pointerCoordinates\n ? {\n top: pointerCoordinates.y,\n bottom: pointerCoordinates.y,\n left: pointerCoordinates.x,\n right: pointerCoordinates.x,\n }\n : null;\n case AutoScrollActivator.DraggableRect:\n return activeNodeRect;\n }\n }, [activator, activeNodeRect, pointerCoordinates]);\n\n const autoScroll = useCallback(() => {\n const scrollContainer = scrollContainerRef.current;\n\n if (!scrollContainer) {\n return;\n }\n\n const scrollLeft = scrollSpeed.current.x * scrollDirection.current.x;\n const scrollTop = scrollSpeed.current.y * scrollDirection.current.y;\n\n scrollContainer.scrollBy(scrollLeft, scrollTop);\n }, []);\n\n useEffect(() => {\n const [scrollableAncestors, scrollableAncestorsRects] = sortedScrollableAncestorsWithRects;\n\n if (!enabled || !scrollableAncestors.length || !rect) {\n clearAutoScrollInterval();\n return;\n }\n\n for (const [index, scrollContainer] of scrollableAncestors.entries()) {\n if (!scrollContainer || canScroll?.(scrollContainer) === false) {\n continue;\n }\n\n const scrollContainerRect = scrollableAncestorsRects[index];\n\n if (!scrollContainerRect) {\n continue;\n }\n\n const { direction, speed } = getScrollDirectionAndSpeed(\n scrollContainer,\n scrollContainerRect,\n rect,\n acceleration,\n threshold\n );\n\n for (const axis of [\"x\", \"y\"] as const) {\n if (!scrollIntent[axis][direction[axis] as Direction]) {\n speed[axis] = 0;\n direction[axis] = 0;\n }\n }\n\n if (speed.x > 0 || speed.y > 0) {\n clearAutoScrollInterval();\n setAutoScrollInterval(autoScroll, interval);\n\n scrollContainerRef.current = scrollContainer;\n scrollSpeed.current = speed;\n scrollDirection.current = direction;\n return;\n }\n }\n\n scrollSpeed.current = { x: 0, y: 0 };\n scrollDirection.current = { x: 0, y: 0 };\n\n clearAutoScrollInterval();\n }, [\n acceleration,\n autoScroll,\n canScroll,\n enabled,\n interval,\n rect,\n scrollableAncestors,\n sortedScrollableAncestorsWithRects,\n threshold,\n clearAutoScrollInterval,\n setAutoScrollInterval,\n\n ...Object.entries(rect || {}),\n ...Object.entries(scrollIntent),\n ...Object.entries(threshold || {}),\n ]);\n}\n\ninterface UseAutoScrollerParams {\n enabled: boolean;\n pointerCoordinates: Coordinates | null;\n delta: Coordinates;\n acceleration?: number;\n activator?: AutoScrollActivator;\n canScroll?: CanScroll;\n interval?: number;\n activeNodeRect: ClientRect | null;\n scrollableAncestors: Element[];\n scrollableAncestorsRects: ClientRect[];\n layoutShiftCompensation?:\n | boolean\n | {\n x: boolean;\n y: boolean;\n };\n order?: TraversalOrder;\n threshold?: {\n x: number;\n y: number;\n };\n}\n\ninterface ScrollDirection {\n x: 0 | Direction;\n y: 0 | Direction;\n}\n\ntype CanScroll = (element: Element) => boolean;\n"],"mappings":";;;;;;AAmBA,SAAgBO,EAAgBC,GAA6B;CAC3D,IAAM,EACJC,iBACAC,eAAA,GACAC,cACAC,YACAC,cAAW,GACXC,uBACAC,WAAA,GACAC,UACAC,cACAC,mBACAC,wBACAC,gCACEZ,GAEE,CAACa,GAAuBC,KAA2BjB,EAAY,GAE/DkB,IAAejB,EAAgB;EAAEU;EAAO,UAAU,CAACJ;CAAQ,CAAC,GAC5DY,IAAcrB,EAAoB;EAAE,GAAG;EAAG,GAAG;CAAE,CAAC,GAChDsB,IAAkBtB,EAAwB;EAAE,GAAG;EAAG,GAAG;CAAE,CAAC,GACxDuB,IAAqBvB,EAAuB,IAAI,GAChDwB,IAAqCzB,QAEvCa,MAAA,IACI,CAAC,CAAC,GAAGI,CAAmB,CAAC,CAAC,QAAQ,GAAG,CAAC,GAAGC,CAAwB,CAAC,CAAC,QAAQ,CAAC,IAC5E,CAAC,CAAC,GAAGD,CAAmB,GAAG,CAAC,GAAGC,CAAwB,CAAC,GAC9D;EAACL;EAAOI;EAAqBC;CAAwB,CACvD,GAEMQ,IAAO1B,QAAc;EACzB,QAAQQ,GAAR;GACE,KAAA,GACE,OAAOI,IACH;IACE,KAAKA,EAAmB;IACxB,QAAQ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EACAV;EACAK;EACAD;EAEA,GAAG,OAAO,QAAQO,KAAQ,CAAC,CAAC;EAC5B,GAAG,OAAO,QAAQL,CAAY;EAC9B,GAAG,OAAO,QAAQN,KAAa,CAAC,CAAC;CACnC,CAAC;AACH"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState as e } from "react";
|
|
3
|
+
import { getCalendarSize as t } from "@weekwise/core";
|
|
4
|
+
import n from "./useIsomorphicLayoutEffect.js";
|
|
5
|
+
import r from "./useResizeObserver.js";
|
|
6
|
+
// src/hooks/useCalendarSize.ts
|
|
7
|
+
function i(i) {
|
|
8
|
+
let [a, o] = e("regular"), s = r(([e]) => {
|
|
9
|
+
if (!e) return;
|
|
10
|
+
let n = e.borderBoxSize?.[0]?.inlineSize ?? e.contentRect.width;
|
|
11
|
+
o(t(n));
|
|
12
|
+
});
|
|
13
|
+
return n(() => {
|
|
14
|
+
let e = i.current;
|
|
15
|
+
if (e) return o(t(e.getBoundingClientRect().width)), s?.observe(e), () => s?.unobserve(e);
|
|
16
|
+
}, [s, i]), a;
|
|
17
|
+
}
|
|
18
|
+
export { i as default };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=useCalendarSize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCalendarSize.js","names":["useState","getCalendarSize","useIsomorphicLayoutEffect","useResizeObserver","useCalendarSize","ref","size","setSize","observer","entry","width","element"],"sources":["../../src/hooks/useCalendarSize.ts"],"sourcesContent":["import { useState, type RefObject } from \"react\";\n\nimport { getCalendarSize, type CalendarSize } from \"@weekwise/core\";\n\nimport useIsomorphicLayoutEffect from \"./useIsomorphicLayoutEffect\";\nimport useResizeObserver from \"./useResizeObserver\";\n\n/**\n * Layout for the width of `ref`'s element, kept up to date as it is resized. `regular` on\n * the server and until the element is measured.\n */\nexport default function useCalendarSize(ref: RefObject<HTMLElement | null>): CalendarSize {\n const [size, setSize] = useState<CalendarSize>(\"regular\");\n\n const observer = useResizeObserver(([entry]) => {\n if (!entry) return;\n const width = entry.borderBoxSize?.[0]?.inlineSize ?? entry.contentRect.width;\n setSize(getCalendarSize(width));\n });\n\n useIsomorphicLayoutEffect(() => {\n const element = ref.current;\n if (!element) return;\n // before the first paint, so the regular layout does not flash\n setSize(getCalendarSize(element.getBoundingClientRect().width));\n observer?.observe(element);\n return () => observer?.unobserve(element);\n }, [observer, ref]);\n\n return size;\n}\n"],"mappings":";;;;;;AAWA,SAAwBI,EAAgBC,GAAkD;CACxF,IAAM,CAACC,GAAMC,KAAWP,EAAuB,SAAS,GAElDQ,IAAWL,GAAmB,CAACM,OAAW;EAC9C,IAAI,CAACA,GAAO;EACZ,IAAMC,IAAQD,EAAM,gBAAgB,EAAE,EAAE,cAAcA,EAAM,YAAY;EACxEF,EAAQN,EAAgBS,CAAK,CAAC;CAChC,CAAC;CAWD,OATAR,QAAgC;EAC9B,IAAMS,IAAUN,EAAI;EACpB,IAAKM,GAIL,OAFAJ,EAAQN,EAAgBU,EAAQ,sBAAsB,CAAC,CAAC,KAAK,CAAC,GAC9DH,GAAU,QAAQG,CAAO,SACZH,GAAU,UAAUG,CAAO;CAC1C,GAAG,CAACH,GAAUH,CAAG,CAAC,GAEXC;AACT"}
|
|
@@ -3,5 +3,5 @@ export default function useCalendarValue<TDate>(params: UseCalendarValueParams<T
|
|
|
3
3
|
view: CalendarView;
|
|
4
4
|
viewValue: TDate;
|
|
5
5
|
changeViewValue: (newValue: TDate, view: CalendarView) => void;
|
|
6
|
-
changeView: (
|
|
6
|
+
changeView: (newView: CalendarView) => void;
|
|
7
7
|
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback as e, useEffect as t, useRef as n } from "react";
|
|
3
|
+
import r from "./useControlled.js";
|
|
4
|
+
import i from "./useCurrentRef.js";
|
|
5
|
+
import a from "./useEventCallback.js";
|
|
6
|
+
import { getViewChangeTarget as o, isDevEnvironment as s, normalizeViewValue as c, resolveView as l, transferDay as u } from "@weekwise/core";
|
|
7
|
+
// src/hooks/useCalendarValue.ts
|
|
8
|
+
function d(d) {
|
|
9
|
+
let { views: f, view: p, defaultView: m, startWeek: h, viewValue: g, defaultViewValue: _, dateUtils: v, onChangeView: y, onChangeViewValue: b } = d, [x, S] = r({
|
|
10
|
+
controlled: p,
|
|
11
|
+
default: m,
|
|
12
|
+
initialState: "week"
|
|
13
|
+
}), C = l(f, x), w = p === void 0 || f.includes(p);
|
|
14
|
+
t(() => {
|
|
15
|
+
s && !w && console.warn(`Calendar: the ${p} view is not among the calendar's views; ${C} is shown.`);
|
|
16
|
+
}, [
|
|
17
|
+
C,
|
|
18
|
+
w,
|
|
19
|
+
p
|
|
20
|
+
]);
|
|
21
|
+
let T = e((e, t) => c(v, e, t, h), [v, h]), [E, D] = r({
|
|
22
|
+
controlled: g,
|
|
23
|
+
default: _,
|
|
24
|
+
initialState: T(C)
|
|
25
|
+
}), O = a((e, t) => {
|
|
26
|
+
D(e), b?.(e, t);
|
|
27
|
+
}), k = a((e) => {
|
|
28
|
+
f.includes(e) && (S(e), y?.(e));
|
|
29
|
+
}), A = i(E), j = n(C), M = n(h), N = n(v);
|
|
30
|
+
return t(() => {
|
|
31
|
+
let e = j.current, t = M.current !== h, n = N.current, r = n === v ? A.current : u(n, v, A.current);
|
|
32
|
+
j.current = C, M.current = h, N.current = v;
|
|
33
|
+
let i = e === C && !t ? T(C, r) : o(v, e, C, r, h);
|
|
34
|
+
O(i, C);
|
|
35
|
+
}, [
|
|
36
|
+
T,
|
|
37
|
+
O,
|
|
38
|
+
C,
|
|
39
|
+
A,
|
|
40
|
+
v,
|
|
41
|
+
h
|
|
42
|
+
]), {
|
|
43
|
+
view: C,
|
|
44
|
+
viewValue: E,
|
|
45
|
+
changeViewValue: O,
|
|
46
|
+
changeView: k
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export { d as default };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=useCalendarValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCalendarValue.js","names":["useCallback","useEffect","useRef","useControlled","useCurrentRef","useEventCallback","getViewChangeTarget","isDevEnvironment","normalizeViewValue","resolveView","transferDay","useCalendarValue","params","views","view","defaultView","startWeek","viewValue","defaultViewValue","dateUtils","onChangeView","onChangeViewValue","requestedView","setControlledView","controlledView","isViewOffered","calculateViewValue","controlledViewValue","setControlledViewValue","changeViewValue","newValue","changeView","newView","currentViewValueRef","previousViewRef","previousStartWeekRef","previousDateUtilsRef","fromView","startWeekChanged","previousDateUtils","nextValue"],"sources":["../../src/hooks/useCalendarValue.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from \"react\";\n\nimport { useControlled, useCurrentRef, useEventCallback } from \"../hooks\";\nimport { getViewChangeTarget, isDevEnvironment, normalizeViewValue, resolveView, transferDay } from \"@weekwise/core\";\n\nimport type { CalendarView, UseCalendarValueParams } from \"../Calendar.types\";\n\nexport default function useCalendarValue<TDate>(params: UseCalendarValueParams<TDate>) {\n const {\n views,\n view,\n defaultView,\n startWeek,\n viewValue,\n defaultViewValue,\n dateUtils,\n onChangeView,\n onChangeViewValue,\n } = params;\n\n const [requestedView, setControlledView] = useControlled<CalendarView>({\n controlled: view,\n default: defaultView,\n initialState: \"week\",\n });\n // a view that is not offered shows as week, or the first view offered\n const controlledView = resolveView(views, requestedView);\n\n const isViewOffered = view === undefined || views.includes(view);\n useEffect(() => {\n if (isDevEnvironment && !isViewOffered) {\n console.warn(`Calendar: the ${view} view is not among the calendar's views; ${controlledView} is shown.`);\n }\n }, [controlledView, isViewOffered, view]);\n\n const calculateViewValue = useCallback(\n (view: CalendarView, viewValue?: TDate) => normalizeViewValue(dateUtils, view, viewValue, startWeek),\n [dateUtils, startWeek]\n );\n\n const [controlledViewValue, setControlledViewValue] = useControlled({\n controlled: viewValue,\n default: defaultViewValue,\n initialState: calculateViewValue(controlledView),\n });\n\n const changeViewValue = useEventCallback((newValue: TDate, view: CalendarView) => {\n setControlledViewValue(newValue);\n onChangeViewValue?.(newValue, view);\n });\n\n const changeView = useEventCallback((newView: CalendarView) => {\n if (!views.includes(newView)) return;\n setControlledView(newView);\n onChangeView?.(newView);\n });\n\n const currentViewValueRef = useCurrentRef(controlledViewValue);\n const previousViewRef = useRef(controlledView);\n const previousStartWeekRef = useRef(startWeek);\n const previousDateUtilsRef = useRef(dateUtils);\n useEffect(() => {\n const fromView = previousViewRef.current;\n const startWeekChanged = previousStartWeekRef.current !== startWeek;\n // another adapter (e.g. another time zone): keep the day the user saw\n const previousDateUtils = previousDateUtilsRef.current;\n const viewValue =\n previousDateUtils === dateUtils\n ? currentViewValueRef.current\n : transferDay(previousDateUtils, dateUtils, currentViewValueRef.current);\n previousViewRef.current = controlledView;\n previousStartWeekRef.current = startWeek;\n previousDateUtilsRef.current = dateUtils;\n // On a view switch, anchor on today / the middle of the week instead of the\n // first visible day, so week → month does not jump to the previous month.\n // A new first day of the week (e.g. another locale) re-anchors the same way:\n // the old first day may belong to the previous week under the new one.\n const nextValue =\n fromView === controlledView && !startWeekChanged\n ? calculateViewValue(controlledView, viewValue)\n : getViewChangeTarget(dateUtils, fromView, controlledView, viewValue, startWeek);\n changeViewValue(nextValue, controlledView);\n }, [calculateViewValue, changeViewValue, controlledView, currentViewValueRef, dateUtils, startWeek]);\n\n return {\n view: controlledView,\n viewValue: controlledViewValue,\n changeViewValue,\n changeView,\n };\n}\n"],"mappings":";;;;;;;AAOA,SAAwBW,EAAwBC,GAAuC;CACrF,IAAM,EACJC,UACAC,SACAC,gBACAC,cACAC,cACAC,qBACAC,cACAC,iBACAC,yBACET,GAEE,CAACU,GAAeC,KAAqBpB,EAA4B;EACrE,YAAYW;EACZ,SAASC;EACT,cAAc;CAChB,CAAC,GAEKS,IAAiBf,EAAYI,GAAOS,CAAa,GAEjDG,IAAgBX,MAAS,KAAA,KAAaD,EAAM,SAASC,CAAI;CAC/Db,QAAgB;EACVM,KAAoB,CAACkB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
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState as e } from "react";
|
|
3
|
+
import { useCalendarDateUtils as t } from "../date-localization/useDateUtils.js";
|
|
4
|
+
import n from "./useIsomorphicLayoutEffect.js";
|
|
5
|
+
import { useCalendarContext as r } from "../contexts/CalendarContext.js";
|
|
6
|
+
import { useDayWeekViewContext as i } from "../contexts/DayWeekViewContext.js";
|
|
7
|
+
// src/hooks/useCanResizeEvent.ts
|
|
8
|
+
function a(a, o) {
|
|
9
|
+
let [s, c] = e(!0), { preventOutBoundsChanges: l } = r(), { isBefore: u, isToday: d } = t(), { getTimeFrame: f } = i();
|
|
10
|
+
return n(() => {
|
|
11
|
+
if (o && l) {
|
|
12
|
+
if (u(a) && !d(a)) c(!1);
|
|
13
|
+
else if (d(a)) {
|
|
14
|
+
let { height: e, y: t } = o, n = e + t, [r, i] = f(a);
|
|
15
|
+
c(n > r && t < i);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}, [
|
|
19
|
+
a,
|
|
20
|
+
o,
|
|
21
|
+
f,
|
|
22
|
+
l,
|
|
23
|
+
u,
|
|
24
|
+
d
|
|
25
|
+
]), s;
|
|
26
|
+
}
|
|
27
|
+
export { a as default };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=useCanResizeEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCanResizeEvent.js","names":["useState","useCalendarDateUtils","useIsomorphicLayoutEffect","useCalendarContext","useDayWeekViewContext","useCanResizeEvent","eventDate","absRect","canResize","setCanResize","preventOutBoundsChanges","isBefore","isToday","getTimeFrame","height","y","bottomRect","bottomEdge","topEdge"],"sources":["../../src/hooks/useCanResizeEvent.ts"],"sourcesContent":["import type { CalendarDate } from \"@weekwise/core\";\nimport { useState } from \"react\";\n\nimport { useCalendarDateUtils } from \"../date-localization\";\nimport { useIsomorphicLayoutEffect } from \"../hooks\";\n\nimport { useCalendarContext } from \"../contexts/CalendarContext\";\nimport { useDayWeekViewContext } from \"../contexts/DayWeekViewContext\";\nimport type { MeasuredEventData } from \"../components/day-week-view\";\n\nexport default function useCanResizeEvent(eventDate: CalendarDate, absRect: MeasuredEventData[\"rect\"] | null) {\n const [canResize, setCanResize] = useState(true);\n const { preventOutBoundsChanges } = useCalendarContext();\n const { isBefore, isToday } = useCalendarDateUtils();\n const { getTimeFrame } = useDayWeekViewContext();\n\n useIsomorphicLayoutEffect(() => {\n // if preventOutBoundsChanges false then we can resize every event\n if (!absRect || !preventOutBoundsChanges) {\n return;\n }\n\n // if event is before today and not today then we can't resize\n if (isBefore(eventDate) && !isToday(eventDate)) {\n // oxlint-disable-next-line react-hooks/set-state-in-effect\n setCanResize(false);\n } else if (isToday(eventDate)) {\n // if is today then check if event is in time frame,\n // between current time and and of the day\n const { height, y } = absRect;\n const bottomRect = height + y;\n const [bottomEdge, topEdge] = getTimeFrame(eventDate);\n setCanResize(bottomRect > bottomEdge && y < topEdge);\n }\n }, [eventDate, absRect, getTimeFrame, preventOutBoundsChanges, isBefore, isToday]);\n\n return canResize;\n}\n"],"mappings":";;;;;;;AAUA,SAAwBK,EAAkBC,GAAyBC,GAA2C;CAC5G,IAAM,CAACC,GAAWC,KAAgBT,EAAS,EAAI,GACzC,EAAEU,+BAA4BP,EAAmB,GACjD,EAAEQ,aAAUC,eAAYX,EAAqB,GAC7C,EAAEY,oBAAiBT,EAAsB;CAsB/C,OApBAF,QAAgC;EAE9B,IAAKK,KAAYG,GAKjB;OAAIC,EAASL,CAAS,KAAK,CAACM,EAAQN,CAAS,GAE3CG,EAAa,EAAK;QACb,IAAIG,EAAQN,CAAS,GAAG;IAG7B,IAAM,EAAEQ,WAAQC,SAAMR,GAChBS,IAAaF,IAASC,GACtB,CAACE,GAAYC,KAAWL,EAAaP,CAAS;IACpDG,EAAaO,IAAaC,KAAcF,IAAIG,CAAO;GACrD;;CACF,GAAG;EAACZ;EAAWC;EAASM;EAAcH;EAAyBC;EAAUC;CAAO,CAAC,GAE1EJ;AACT"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMemo as e, useRef as t } from "react";
|
|
3
|
+
import n from "./useCurrentRef.js";
|
|
4
|
+
// src/hooks/useComputed.ts
|
|
5
|
+
function r(r, i) {
|
|
6
|
+
let a = t(void 0), o = n(r);
|
|
7
|
+
return e(() => {
|
|
8
|
+
let e = o.current(a.current);
|
|
9
|
+
return a.current = e, e;
|
|
10
|
+
}, i);
|
|
11
|
+
}
|
|
12
|
+
export { r as default };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=useComputed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useComputed.js","names":["useMemo","useRef","useCurrentRef","useComputed","cb","deps","valueRef","cbRef","newValue"],"sources":["../../src/hooks/useComputed.ts"],"sourcesContent":["import { useMemo, useRef, type DependencyList } from \"react\";\n\nimport useCurrentRef from \"./useCurrentRef\";\n\nexport default function useComputed<T>(cb: (prevValue: T | undefined) => T, deps: DependencyList) {\n const valueRef = useRef<T>(undefined);\n const cbRef = useCurrentRef(cb);\n\n return useMemo(\n () => {\n const newValue = cbRef.current(valueRef.current);\n valueRef.current = newValue;\n\n return newValue;\n },\n // cbRef can be ignored because it will never change\n // oxlint-disable-next-line react-hooks/exhaustive-deps, react-hooks/use-memo\n deps\n );\n}\n"],"mappings":";;;;AAIA,SAAwBG,EAAeC,GAAqCC,GAAsB;CAChG,IAAMC,IAAWL,EAAU,KAAA,CAAS,GAC9BM,IAAQL,EAAcE,CAAE;CAE9B,OAAOJ,QACC;EACJ,IAAMQ,IAAWD,EAAM,QAAQD,EAAS,OAAO;EAG/C,OAFAA,EAAS,UAAUE,GAEZA;CACT,GAGAH,CACF;AACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { isDevEnvironment as e } from "@weekwise/core";
|
|
3
|
+
import { useCallback as t, useState as n } from "react";
|
|
4
|
+
import { useAssert as r, useIsControlled as i } from "./useControlled.utils.js";
|
|
5
|
+
// src/hooks/useControlled.ts
|
|
6
|
+
function a(a) {
|
|
7
|
+
let { controlled: o, default: s } = a, [c, l] = n(() => s === void 0 && "initialState" in a && a.initialState !== void 0 ? a.initialState : s), [u] = n(s), d = i(o);
|
|
8
|
+
e && r(d, o, u, s);
|
|
9
|
+
let f = t((e) => {
|
|
10
|
+
d || l(e);
|
|
11
|
+
}, [d]);
|
|
12
|
+
return [
|
|
13
|
+
d ? o : c,
|
|
14
|
+
f,
|
|
15
|
+
d
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
export { a as default };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=useControlled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useControlled.js","names":["isDevEnvironment","useCallback","useState","useAssert","useIsControlled","useControlled","params","controlled","defaultValueProp","valueState","setValueState","defaultValue","isControlled","setValueIfUncontrolled","newValue"],"sources":["../../src/hooks/useControlled.ts"],"sourcesContent":["import { isDevEnvironment } from \"@weekwise/core\";\nimport { useCallback, useState, type Dispatch, type SetStateAction } from \"react\";\n\nimport type { UseControlledParams, UseControlledWithInitialParams } from \"./useControlled.types\";\nimport { useAssert, useIsControlled } from \"./useControlled.utils\";\n\n/**\n * Creates a controlled state with an uncontrolled fallback.\n *\n * If `controlled` is defined, `useControlled` will return the controlled value and an\n * identity function as the update function. If `controlled` is `undefined`, `useControlled`\n * will return the `defaultValue` and a state update function.\n *\n * This hook is useful when you want to make a component that can be either controlled or\n * uncontrolled, depending on whether the user provides a `value` or `defaultValue` prop.\n *\n * @param params - The parameters of the hook.\n * @param params.controlled - The controlled value.\n * @param params.default - The default value.\n * @returns A tuple of the value and the update function.\n */\nexport default function useControlled<T>(\n params: UseControlledParams<T>\n): [T | undefined, Dispatch<SetStateAction<T | undefined>>, boolean];\n/**\n * Creates a controlled state with an uncontrolled fallback and an `initialState`.\n *\n * This hook is useful when you want to make a component that can be either controlled or\n * uncontrolled, depending on whether the user provides a `value` or `defaultValue` prop. The\n * `initialState` is used as the initial value of the state, if the component is uncontrolled.\n *\n * The third element of the returned tuple is a boolean indicating whether the component is\n * controlled or uncontrolled.\n *\n * @param params - The parameters of the hook.\n * @param params.controlled - The controlled value.\n * @param params.default - The default value.\n * @param params.initialState - The initial state.\n * @returns A tuple of the value, the update function and a boolean indicating whether the\n * component is controlled or uncontrolled.\n */\nexport default function useControlled<T>(\n params: UseControlledWithInitialParams<T>\n): [T, Dispatch<SetStateAction<T>>, boolean];\nexport default function useControlled<T>(params: UseControlledParams<T> | UseControlledWithInitialParams<T>) {\n const { controlled, default: defaultValueProp } = params;\n const [valueState, setValueState] = useState(() => {\n if (defaultValueProp === undefined && \"initialState\" in params && params.initialState !== undefined) {\n return params.initialState;\n }\n return defaultValueProp;\n });\n const [defaultValue] = useState<T | undefined>(defaultValueProp);\n\n const isControlled = useIsControlled(controlled);\n\n if (isDevEnvironment) {\n // oxlint-disable-next-line react-hooks/rules-of-hooks\n useAssert(isControlled, controlled, defaultValue, defaultValueProp);\n }\n\n const setValueIfUncontrolled: Dispatch<SetStateAction<T | undefined>> = useCallback(\n (newValue) => {\n if (!isControlled) {\n setValueState(newValue);\n }\n },\n [isControlled]\n );\n return [isControlled ? controlled : valueState, setValueIfUncontrolled, isControlled];\n}\n"],"mappings":";;;;;AA4CA,SAAwBK,EAAiBC,GAAoE;CAC3G,IAAM,EAAEC,eAAY,SAASC,MAAqBF,GAC5C,CAACG,GAAYC,KAAiBR,QAC9BM,MAAqB,KAAA,KAAa,kBAAkBF,KAAUA,EAAO,iBAAiB,KAAA,IACjFA,EAAO,eAETE,CACR,GACK,CAACG,KAAgBT,EAAwBM,CAAgB,GAEzDI,IAAeR,EAAgBG,CAAU;CAE3CP,KAEFG,EAAUS,GAAcL,GAAYI,GAAcH,CAAgB;CAGpE,IAAMK,IAAkEZ,GACrEa,MAAa;EACPF,KACHF,EAAcI,CAAQ;CAE1B,GACA,CAACF,CAAY,CACf;CACA,OAAO;EAACA,IAAeL,IAAaE;EAAYI;EAAwBD;CAAY;AACtF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect as e, useRef as t, useState as n } from "react";
|
|
3
|
+
// src/hooks/useControlled.utils.ts
|
|
4
|
+
function r(e) {
|
|
5
|
+
let [t] = n(() => e !== void 0);
|
|
6
|
+
return t;
|
|
7
|
+
}
|
|
8
|
+
function i(n, r, i, a) {
|
|
9
|
+
let o = t(/* @__PURE__ */ Error());
|
|
10
|
+
e(() => {
|
|
11
|
+
if (n !== (r !== void 0)) throw Error(`
|
|
12
|
+
[useControlled]:
|
|
13
|
+
A component is changing ${n ? "a controlled value to be uncontrolled" : "an uncontrolled value to be controlled"}. This is likely caused by the value changing from ${n ? "defined to an undefined" : "undefined to a defined"} value, which should not happen.
|
|
14
|
+
Decide between using a controlled or uncontrolled input element for the lifetime of the component.
|
|
15
|
+
More info: https://reactjs.org/link/controlled-components
|
|
16
|
+
${o.current.stack}
|
|
17
|
+
`);
|
|
18
|
+
}, [n, r]), e(() => {
|
|
19
|
+
if (!n && i !== a) throw Error(`
|
|
20
|
+
[useControlled]:
|
|
21
|
+
A component is changing the default state of an uncontrolled value after being initialized.
|
|
22
|
+
To suppress this warning opt to use a controlled value.
|
|
23
|
+
More info: https://reactjs.org/link/controlled-components
|
|
24
|
+
${o.current.stack}`);
|
|
25
|
+
}, [
|
|
26
|
+
a,
|
|
27
|
+
i,
|
|
28
|
+
n
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
export { i as useAssert, r as useIsControlled };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=useControlled.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useControlled.utils.js","names":["useEffect","useRef","useState","useIsControlled","controlledValue","isControlled","useAssert","defaultValue","defaultValueProp","error"],"sources":["../../src/hooks/useControlled.utils.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\n\n/**\n * Helper hook to handle previous comparison of controlled/uncontrolled\n * Prints an error when isControlled value switches between subsequent renders\n * @returns - whether the value is controlled\n */\nexport function useIsControlled<T>(controlledValue: T | undefined): controlledValue is T {\n const [isControlled] = useState<boolean>(() => controlledValue !== undefined);\n return isControlled;\n}\n\nexport function useAssert<T>(\n isControlled: boolean,\n controlledValue: T | undefined,\n defaultValue: T | undefined,\n defaultValueProp: T | undefined\n) {\n const error = useRef(new Error());\n // We don't want these warnings in production even though it is against native behaviour\n\n useEffect(() => {\n if (isControlled !== (controlledValue !== undefined)) {\n const controlWarning = isControlled\n ? \"a controlled value to be uncontrolled\"\n : \"an uncontrolled value to be controlled\";\n\n const undefinedWarning = isControlled ? \"defined to an undefined\" : \"undefined to a defined\";\n\n throw new Error(`\n [useControlled]:\n A component is changing ${controlWarning}. This is likely caused by the value changing from ${undefinedWarning} value, which should not happen.\n Decide between using a controlled or uncontrolled input element for the lifetime of the component.\n More info: https://reactjs.org/link/controlled-components\n ${error.current.stack}\n `);\n }\n }, [isControlled, controlledValue]);\n\n useEffect(() => {\n if (!isControlled && defaultValue !== defaultValueProp) {\n throw new Error(`\n [useControlled]:\n A component is changing the default state of an uncontrolled value after being initialized.\n To suppress this warning opt to use a controlled value.\n More info: https://reactjs.org/link/controlled-components\n ${error.current.stack}`);\n }\n }, [defaultValueProp, defaultValue, isControlled]);\n}\n"],"mappings":";;;AAOA,SAAgBG,EAAmBC,GAAsD;CACvF,IAAM,CAACC,KAAgBH,QAAwBE,MAAoB,KAAA,CAAS;CAC5E,OAAOC;AACT;AAEA,SAAgBC,EACdD,GACAD,GACAG,GACAC,GACA;CACA,IAAMC,IAAQR,EAAO,gBAAI,MAAM,CAAC;CAGhCD,QAAgB;EACd,IAAIK,OAAkBD,MAAoB,KAAA,IAOxC,MAAU,MAAM;;kCANOC,IACnB,0CACA,yCAMuC,qDAJlBA,IAAe,4BAA4B,yBAI6C;;;UAG7GI,EAAM,QAAQ,MAAM;OACvB;CAEL,GAAG,CAACJ,GAAcD,CAAe,CAAC,GAElCJ,QAAgB;EACd,IAAI,CAACK,KAAgBE,MAAiBC,GACpC,MAAU,MAAM;;;;;UAKZC,EAAM,QAAQ,OAAO;CAE7B,GAAG;EAACD;EAAkBD;EAAcF;CAAY,CAAC;AACnD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCurrentRef.js","names":["useRef","useCurrentRef","value","currentRef"],"sources":["../../src/hooks/useCurrentRef.ts"],"sourcesContent":["import { useRef } from \"react\";\n\nexport default function useCurrentRef<T>(value: T): { readonly current: T } {\n const currentRef = useRef(value);\n currentRef.current = value;\n\n return currentRef;\n}\n"],"mappings":";;;AAEA,SAAwBC,EAAiBC,GAAmC;CAC1E,IAAMC,IAAaH,EAAOE,CAAK;CAG/B,OAFAC,EAAW,UAAUD,GAEdC;AACT"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect as e } from "react";
|
|
3
|
+
// src/hooks/useDocumentCursor.ts
|
|
4
|
+
function t(t) {
|
|
5
|
+
e(() => {
|
|
6
|
+
if (!t) return;
|
|
7
|
+
let e = `ww-cursor-${t}`, n = document.documentElement;
|
|
8
|
+
return n.classList.add(e), () => n.classList.remove(e);
|
|
9
|
+
}, [t]);
|
|
10
|
+
}
|
|
11
|
+
export { t as default };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=useDocumentCursor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDocumentCursor.js","names":["useEffect","useDocumentCursor","cursor","className","root"],"sources":["../../src/hooks/useDocumentCursor.ts"],"sourcesContent":["import { useEffect } from \"react\";\n\n/** Cursors set on the whole page while a gesture runs: see the `ww-cursor-*` classes in Calendar.module.css. */\nexport type DocumentCursor = \"grabbing\" | \"not-allowed\";\n\n/**\n * Shows `cursor` over the whole page, the calendar, its overlays and outside it, until it is\n * `null` or the component unmounts. The page's elements keep their own cursors otherwise.\n */\nexport default function useDocumentCursor(cursor: DocumentCursor | null) {\n useEffect(() => {\n if (!cursor) return;\n\n const className = `ww-cursor-${cursor}`;\n const root = document.documentElement;\n root.classList.add(className);\n return () => root.classList.remove(className);\n }, [cursor]);\n}\n"],"mappings":";;;AASA,SAAwBC,EAAkBC,GAA+B;CACvEF,QAAgB;EACd,IAAI,CAACE,GAAQ;EAEb,IAAMC,IAAY,aAAaD,KACzBE,IAAO,SAAS;EAEtB,OADAA,EAAK,UAAU,IAAID,CAAS,SACfC,EAAK,UAAU,OAAOD,CAAS;CAC9C,GAAG,CAACD,CAAM,CAAC;AACb"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useInsertionEffect as e } from "react";
|
|
3
|
+
import t from "./useRefWithInit.js";
|
|
4
|
+
import { createStableCallback as n } from "./useEventCallback.utils.js";
|
|
5
|
+
// src/hooks/useEventCallback.ts
|
|
6
|
+
function r(r) {
|
|
7
|
+
let i = t(n).current;
|
|
8
|
+
return i.next = r, e(i.effect), i.trampoline;
|
|
9
|
+
}
|
|
10
|
+
export { r as default };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=useEventCallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEventCallback.js","names":["useInsertionEffect","useRefWithInit","createStableCallback","useEventCallback","callback","stable"],"sources":["../../src/hooks/useEventCallback.ts"],"sourcesContent":["import { useInsertionEffect } from \"react\";\n\nimport useRefWithInit from \"./useRefWithInit\";\nimport { createStableCallback } from \"./useEventCallback.utils\";\n\nexport default function useEventCallback<T extends (...args: any[]) => any>(callback: T | undefined): T {\n const stable = useRefWithInit(createStableCallback).current;\n // oxlint-disable-next-line react-hooks/immutability\n stable.next = callback;\n useInsertionEffect(stable.effect);\n return stable.trampoline;\n}\n"],"mappings":";;;;;AAKA,SAAwBG,EAAoDC,GAA4B;CACtG,IAAMC,IAASJ,EAAeC,CAAoB,CAAC,CAAC;CAIpD,OAFAG,EAAO,OAAOD,GACdJ,EAAmBK,EAAO,MAAM,GACzBA,EAAO;AAChB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { isDevEnvironment as e } from "@weekwise/core";
|
|
3
|
+
// src/hooks/useEventCallback.utils.ts
|
|
4
|
+
function t() {
|
|
5
|
+
if (e) throw Error("useEventCallback: Cannot call an event handler while rendering.");
|
|
6
|
+
}
|
|
7
|
+
function n() {
|
|
8
|
+
let e = {
|
|
9
|
+
next: void 0,
|
|
10
|
+
callback: t,
|
|
11
|
+
trampoline: (...t) => e.callback?.(...t),
|
|
12
|
+
effect: () => {
|
|
13
|
+
e.callback = e.next;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
return e;
|
|
17
|
+
}
|
|
18
|
+
export { n as createStableCallback };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=useEventCallback.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEventCallback.utils.js","names":["isDevEnvironment","assertNotCalled","createStableCallback","stable","args"],"sources":["../../src/hooks/useEventCallback.utils.ts"],"sourcesContent":["import { isDevEnvironment } from \"@weekwise/core\";\nimport type { Stable } from \"./useEventCallback.types\";\n\nfunction assertNotCalled() {\n if (isDevEnvironment) {\n throw new Error(\"useEventCallback: Cannot call an event handler while rendering.\");\n }\n}\n\nexport function createStableCallback() {\n const stable: Stable<any> = {\n next: undefined,\n callback: assertNotCalled,\n trampoline: (...args: []) => stable.callback?.(...args),\n effect: () => {\n stable.callback = stable.next;\n },\n };\n return stable;\n}\n"],"mappings":";;;AAGA,SAASC,IAAkB;CACzB,IAAID,GACF,MAAU,MAAM,iEAAiE;AAErF;AAEA,SAAgBE,IAAuB;CACrC,IAAMC,IAAsB;EAC1B,MAAM,KAAA;EACN,UAAUF;EACV,aAAa,GAAGG,MAAaD,EAAO,WAAW,GAAGC,CAAI;EACtD,cAAc;GACZD,EAAO,WAAWA,EAAO;EAC3B;CACF;CACA,OAAOA;AACT"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback as e, useMemo as t, useRef as n, useState as r } from "react";
|
|
3
|
+
import { fromDayMinutes as i, getTimeFrame as a, isPastDay as o, resizeEventRange as s, toDayMinutes as c } from "@weekwise/core";
|
|
4
|
+
import l from "./useDocumentCursor.js";
|
|
5
|
+
import u from "./useEventCallback.js";
|
|
6
|
+
import d from "./useGlobalListeners.js";
|
|
7
|
+
import f from "./useItemsLayout.js";
|
|
8
|
+
// src/hooks/useEventResize.ts
|
|
9
|
+
var p = 1440;
|
|
10
|
+
function m(m) {
|
|
11
|
+
let { days: h, viewportRef: g, columnsRef: _, dateUtils: v, bounds: y, timeStep: b, preventOutBoundsChanges: x } = m, [S, C] = r(null), w = n(null), { addGlobalListener: T, removeGlobalListener: E } = d(), D = f(g, _), O = n(m);
|
|
12
|
+
O.current = m;
|
|
13
|
+
let k = y.hideMinMaxTime ? y.hourMin * 60 : 0, A = y.hideMinMaxTime ? (y.hourMax - y.hourMin) * 60 : p, j = e((e, t) => {
|
|
14
|
+
let n = w.current, r = D.container();
|
|
15
|
+
if (!n || !r) return;
|
|
16
|
+
n.x = e, n.y = t;
|
|
17
|
+
let { disabled: i, getIsDayDisabled: c } = O.current, l = ((e) => Math.round(e / b) * b)(Math.min(Math.max((t - r.top) / r.height * A, 0), A)), u = Math.max(D.nearestIndex(e, t, "x"), 0), d = s({
|
|
18
|
+
start: n.original[0],
|
|
19
|
+
end: n.original[1]
|
|
20
|
+
}, n.edge, u, l, {
|
|
21
|
+
dayCount: h.length,
|
|
22
|
+
bounds: y,
|
|
23
|
+
timeStep: b,
|
|
24
|
+
crossDays: !x || y.hourMin <= 0 && y.hourMax >= 24,
|
|
25
|
+
getFrame: (e) => {
|
|
26
|
+
if (!x) return [0, A];
|
|
27
|
+
let [t, n] = a(v, h[e], y);
|
|
28
|
+
return [Math.ceil(t / b) * b, Math.min(Math.ceil(n / b) * b, A)];
|
|
29
|
+
},
|
|
30
|
+
canEditDay: (e) => !i && !c?.(h[e]) && !(x && o(v, h[e]))
|
|
31
|
+
});
|
|
32
|
+
d && (n.range = d), C({
|
|
33
|
+
key: n.key,
|
|
34
|
+
range: n.range,
|
|
35
|
+
x: e,
|
|
36
|
+
y: t,
|
|
37
|
+
blocked: !d
|
|
38
|
+
});
|
|
39
|
+
}, [
|
|
40
|
+
y,
|
|
41
|
+
v,
|
|
42
|
+
h,
|
|
43
|
+
D,
|
|
44
|
+
x,
|
|
45
|
+
b,
|
|
46
|
+
A
|
|
47
|
+
]), M = u(() => {
|
|
48
|
+
let e = w.current;
|
|
49
|
+
e && j(e.x, e.y);
|
|
50
|
+
}), N = t(() => ({
|
|
51
|
+
start(e, t, n, r) {
|
|
52
|
+
let i = O.current.eventMap.get(e);
|
|
53
|
+
if (!i || !h[0] || !D.measure()) return;
|
|
54
|
+
let a = c(v, h[0], i.date), o = [a, a + i.duration];
|
|
55
|
+
w.current = {
|
|
56
|
+
key: e,
|
|
57
|
+
edge: t,
|
|
58
|
+
original: o,
|
|
59
|
+
range: o,
|
|
60
|
+
x: n,
|
|
61
|
+
y: r
|
|
62
|
+
}, T(document, "scroll", M, !0), C({
|
|
63
|
+
key: e,
|
|
64
|
+
range: o,
|
|
65
|
+
x: n,
|
|
66
|
+
y: r,
|
|
67
|
+
blocked: !1
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
move: j,
|
|
71
|
+
end() {
|
|
72
|
+
let e = w.current;
|
|
73
|
+
if (e && j(e.x, e.y), w.current = null, E(document, "scroll", M, !0), D.release(), C(null), !e) return;
|
|
74
|
+
let [t, n] = e.range;
|
|
75
|
+
if (t === e.original[0] && n === e.original[1]) return;
|
|
76
|
+
let r = Math.floor(t / p);
|
|
77
|
+
O.current.onEventChange(e.key, i(v, h[0], r * p), {
|
|
78
|
+
from: t - r * p,
|
|
79
|
+
duration: n - t
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}), [
|
|
83
|
+
T,
|
|
84
|
+
v,
|
|
85
|
+
h,
|
|
86
|
+
M,
|
|
87
|
+
D,
|
|
88
|
+
E,
|
|
89
|
+
j
|
|
90
|
+
]);
|
|
91
|
+
return l(S?.blocked ? "not-allowed" : null), {
|
|
92
|
+
state: S,
|
|
93
|
+
actions: N,
|
|
94
|
+
previewOf: (e) => {
|
|
95
|
+
let t = Math.floor(e[0] / p);
|
|
96
|
+
return {
|
|
97
|
+
date: i(v, h[0], t * p),
|
|
98
|
+
top: e[0] - t * p - k,
|
|
99
|
+
duration: e[1] - e[0]
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export { m as default };
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=useEventResize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEventResize.js","names":["useCallback","useMemo","useRef","useState","fromDayMinutes","getTimeFrame","isPastDay","resizeEventRange","toDayMinutes","useDocumentCursor","useEventCallback","useGlobalListeners","useItemsLayout","DAY","useEventResize","params","days","viewportRef","columnsRef","dateUtils","bounds","timeStep","preventOutBoundsChanges","state","setState","session","addGlobalListener","removeGlobalListener","layout","paramsRef","offset","timelineMinutes","update","x","y","current","viewport","disabled","getIsDayDisabled","minute","dayIndex","next","idx","top","bottom","handleScroll","actions","key","edge","event","start","original","end","range"],"sources":["../../src/hooks/useEventResize.ts"],"sourcesContent":["import type { CalendarDate } from \"@weekwise/core\";\nimport { useCallback, useMemo, useRef, useState } from \"react\";\nimport type { RefObject } from \"react\";\n\nimport {\n fromDayMinutes,\n getTimeFrame,\n isPastDay,\n resizeEventRange,\n toDayMinutes,\n type DateAdapter,\n type EventChangeInfo,\n type EventKey,\n type EventMap,\n type TimeBounds,\n} from \"@weekwise/core\";\n\nimport useDocumentCursor from \"./useDocumentCursor\";\nimport useEventCallback from \"./useEventCallback\";\nimport useGlobalListeners from \"./useGlobalListeners\";\nimport useItemsLayout from \"./useItemsLayout\";\n\nconst DAY = 24 * 60;\n\nexport type ResizeEdge = \"top\" | \"bottom\";\n\n/** An event being resized: its range in wall-clock minutes from the first visible day. */\nexport interface ResizeState {\n key: EventKey;\n range: [number, number];\n /** Pointer position, for the time preview. */\n x: number;\n y: number;\n /** The pointer is where the edge cannot go; the last valid range stays. */\n blocked: boolean;\n}\n\ninterface ResizeSession {\n key: EventKey;\n edge: ResizeEdge;\n original: [number, number];\n range: [number, number];\n x: number;\n y: number;\n}\n\nexport interface EventResizeActions {\n start: (key: EventKey, edge: ResizeEdge, x: number, y: number) => void;\n move: (x: number, y: number) => void;\n end: () => void;\n}\n\ninterface UseEventResizeParams {\n days: CalendarDate[];\n viewportRef: RefObject<HTMLElement | null>;\n /** The day columns by day index, where the pointer picks the day. */\n columnsRef: { readonly current: readonly (HTMLElement | null)[] };\n dateUtils: DateAdapter<CalendarDate>;\n bounds: TimeBounds;\n timeStep: number;\n preventOutBoundsChanges: boolean;\n disabled: boolean;\n getIsDayDisabled?: (date: CalendarDate) => boolean;\n eventMap: EventMap<unknown, CalendarDate>;\n onEventChange: (key: EventKey, date: CalendarDate, info: EventChangeInfo) => void;\n}\n\n/**\n * Resizes an event by its top or bottom edge, into other days too (like macOS Calendar):\n * dragging the bottom edge into a later day ends the event there, the first day filling\n * to midnight. The view draws the event from {@link ResizeState} while it changes.\n */\nexport default function useEventResize(params: UseEventResizeParams) {\n const { days, viewportRef, columnsRef, dateUtils, bounds, timeStep, preventOutBoundsChanges } = params;\n const [state, setState] = useState<ResizeState | null>(null);\n const session = useRef<ResizeSession | null>(null);\n const { addGlobalListener, removeGlobalListener } = useGlobalListeners();\n // the timeline and its day columns, measured once a resize starts\n const layout = useItemsLayout(viewportRef, columnsRef);\n\n const paramsRef = useRef(params);\n paramsRef.current = params;\n\n const offset = bounds.hideMinMaxTime ? bounds.hourMin * 60 : 0;\n const timelineMinutes = bounds.hideMinMaxTime ? (bounds.hourMax - bounds.hourMin) * 60 : DAY;\n\n const update = useCallback(\n (x: number, y: number) => {\n const current = session.current;\n const viewport = layout.container();\n if (!current || !viewport) return;\n current.x = x;\n current.y = y;\n\n const { disabled, getIsDayDisabled } = paramsRef.current;\n const snap = (minute: number) => Math.round(minute / timeStep) * timeStep;\n const minute = snap(\n Math.min(Math.max(((y - viewport.top) / viewport.height) * timelineMinutes, 0), timelineMinutes)\n );\n\n // The column under the pointer, or the nearest one.\n const dayIndex = Math.max(layout.nearestIndex(x, y, \"x\"), 0);\n\n const next = resizeEventRange(\n { start: current.original[0], end: current.original[1] },\n current.edge,\n dayIndex,\n minute,\n {\n dayCount: days.length,\n bounds,\n timeStep,\n // An event across midnight passes hours a time frame leaves out.\n crossDays: !preventOutBoundsChanges || (bounds.hourMin <= 0 && bounds.hourMax >= 24),\n getFrame: (idx) => {\n if (!preventOutBoundsChanges) return [0, timelineMinutes];\n const [top, bottom] = getTimeFrame(dateUtils, days[idx], bounds);\n return [\n Math.ceil(top / timeStep) * timeStep,\n Math.min(Math.ceil(bottom / timeStep) * timeStep, timelineMinutes),\n ];\n },\n canEditDay: (idx) =>\n !disabled &&\n !getIsDayDisabled?.(days[idx]) &&\n !(preventOutBoundsChanges && isPastDay(dateUtils, days[idx])),\n }\n );\n if (next) current.range = next;\n setState({ key: current.key, range: current.range, x, y, blocked: !next });\n },\n [bounds, dateUtils, days, layout, preventOutBoundsChanges, timeStep, timelineMinutes]\n );\n\n // Auto-scroll moves the timeline under a still pointer: the layout follows, the time under the\n // pointer changes. Stable, so `end` removes the listener `start` added.\n const handleScroll = useEventCallback(() => {\n const current = session.current;\n if (current) update(current.x, current.y);\n });\n\n const actions = useMemo<EventResizeActions>(\n () => ({\n start(key, edge, x, y) {\n const event = paramsRef.current.eventMap.get(key);\n if (!event || !days[0] || !layout.measure()) return;\n const start = toDayMinutes(dateUtils, days[0], event.date);\n const original: [number, number] = [start, start + event.duration];\n session.current = { key, edge, original, range: original, x, y };\n addGlobalListener(document, \"scroll\", handleScroll, true);\n setState({ key, range: original, x, y, blocked: false });\n },\n move: update,\n end() {\n const current = session.current;\n // Auto-scroll may have moved the timeline since the last scroll event (Safari sends them with\n // the next frame): the range is taken from where the timeline is now.\n if (current) update(current.x, current.y);\n session.current = null;\n removeGlobalListener(document, \"scroll\", handleScroll, true);\n layout.release();\n setState(null);\n if (!current) return;\n const [start, end] = current.range;\n if (start === current.original[0] && end === current.original[1]) return;\n const dayIndex = Math.floor(start / DAY);\n paramsRef.current.onEventChange(current.key, fromDayMinutes(dateUtils, days[0], dayIndex * DAY), {\n from: start - dayIndex * DAY,\n duration: end - start,\n });\n },\n }),\n [addGlobalListener, dateUtils, days, handleScroll, layout, removeGlobalListener, update]\n );\n\n // Over a place the edge cannot go: \"not allowed\" cursor on the whole page.\n useDocumentCursor(state?.blocked ? \"not-allowed\" : null);\n\n /** Start of the range: its day and the timeline position in it, for the time preview. */\n const previewOf = (range: [number, number]) => {\n const dayIndex = Math.floor(range[0] / DAY);\n return {\n date: fromDayMinutes(dateUtils, days[0], dayIndex * DAY),\n top: range[0] - dayIndex * DAY - offset,\n duration: range[1] - range[0],\n };\n };\n\n return { state, actions, previewOf };\n}\n"],"mappings":";;;;;;;;AAsBA,IAAMa,IAAM;AAkDZ,SAAwBC,EAAeC,GAA8B;CACnE,IAAM,EAAEC,SAAMC,gBAAaC,eAAYC,cAAWC,WAAQC,aAAUC,+BAA4BP,GAC1F,CAACQ,GAAOC,KAAYrB,EAA6B,IAAI,GACrDsB,IAAUvB,EAA6B,IAAI,GAC3C,EAAEwB,sBAAmBC,4BAAyBhB,EAAmB,GAEjEiB,IAAShB,EAAeK,GAAaC,CAAU,GAE/CW,IAAY3B,EAAOa,CAAM;CAC/Bc,EAAU,UAAUd;CAEpB,IAAMe,IAASV,EAAO,iBAAiBA,EAAO,UAAU,KAAK,GACvDW,IAAkBX,EAAO,kBAAkBA,EAAO,UAAUA,EAAO,WAAW,KAAKP,GAEnFmB,IAAShC,GACZiC,G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eA,OAZAvB,EAAkBc,GAAO,UAAU,gBAAgB,IAAI,GAYhD;EAAEA;EAAOuB;EAAS,YATNO,MAA4B;GAC7C,IAAMb,IAAW,KAAK,MAAMa,EAAM,KAAKxC,CAAG;GAC1C,OAAO;IACL,MAAMT,EAAee,GAAWH,EAAK,IAAIwB,IAAW3B,CAAG;IACvD,KAAKwC,EAAM,KAAKb,IAAW3B,IAAMiB;IACjC,UAAUuB,EAAM,KAAKA,EAAM;GAC7B;EACF;CAEmC;AACrC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect as e, useMemo as t, useState as n } from "react";
|
|
3
|
+
// src/hooks/useGlobalListeners.ts
|
|
4
|
+
function r() {
|
|
5
|
+
let [r] = n(() => ({ current: /* @__PURE__ */ new Map() })), { addGlobalListener: i, removeGlobalListener: a, removeAllGlobalListeners: o } = t(() => {
|
|
6
|
+
function e(e, t, n, i) {
|
|
7
|
+
let a = typeof i != "boolean" && i?.once ? (t) => {
|
|
8
|
+
r.current.delete(n), e instanceof Document ? n.call(e, t) : n(t);
|
|
9
|
+
} : n;
|
|
10
|
+
e.addEventListener(t, n, i), r.current.set(n, {
|
|
11
|
+
type: t,
|
|
12
|
+
target: e,
|
|
13
|
+
fn: a,
|
|
14
|
+
options: i
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function t(e, t, n, i) {
|
|
18
|
+
let a = r.current.get(n)?.fn || n;
|
|
19
|
+
e.removeEventListener(t, a, i), r.current.delete(n);
|
|
20
|
+
}
|
|
21
|
+
function n() {
|
|
22
|
+
r.current.forEach(({ target: e, type: n, options: r }, i) => {
|
|
23
|
+
t(e, n, i, r);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
addGlobalListener: e,
|
|
28
|
+
removeGlobalListener: t,
|
|
29
|
+
removeAllGlobalListeners: n
|
|
30
|
+
};
|
|
31
|
+
}, [r]);
|
|
32
|
+
return e(() => o, [o]), {
|
|
33
|
+
addGlobalListener: i,
|
|
34
|
+
removeGlobalListener: a,
|
|
35
|
+
removeAllGlobalListeners: o
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export { r as default };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=useGlobalListeners.js.map
|