@savvycal/calendar 0.13.0 → 0.14.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.
Files changed (55) hide show
  1. package/README.md +108 -40
  2. package/dist/components/day-grid-view/AllDaySection.d.ts +2 -0
  3. package/dist/components/day-grid-view/AllDaySection.d.ts.map +1 -1
  4. package/dist/components/day-grid-view/AllDaySection.js +111 -75
  5. package/dist/components/day-grid-view/DayColumn.d.ts +2 -24
  6. package/dist/components/day-grid-view/DayColumn.d.ts.map +1 -1
  7. package/dist/components/day-grid-view/DayGridView.d.ts +1 -1
  8. package/dist/components/day-grid-view/DayGridView.d.ts.map +1 -1
  9. package/dist/components/day-grid-view/DayGridView.js +330 -275
  10. package/dist/components/day-grid-view/defaults.d.ts.map +1 -1
  11. package/dist/components/day-grid-view/defaults.js +1 -0
  12. package/dist/components/month-view/MonthView.d.ts.map +1 -1
  13. package/dist/components/month-view/MonthView.js +184 -165
  14. package/dist/components/month-view/MonthWeekRow.d.ts +1 -0
  15. package/dist/components/month-view/MonthWeekRow.d.ts.map +1 -1
  16. package/dist/components/month-view/MonthWeekRow.js +95 -89
  17. package/dist/components/resource-grid-view/ResourceColumn.d.ts +3 -21
  18. package/dist/components/resource-grid-view/ResourceColumn.d.ts.map +1 -1
  19. package/dist/components/resource-grid-view/ResourceColumn.js +13 -6
  20. package/dist/components/resource-grid-view/ResourceGridView.d.ts +1 -1
  21. package/dist/components/resource-grid-view/ResourceGridView.d.ts.map +1 -1
  22. package/dist/components/resource-grid-view/ResourceGridView.js +348 -300
  23. package/dist/components/resource-grid-view/defaults.d.ts.map +1 -1
  24. package/dist/components/resource-grid-view/defaults.js +1 -0
  25. package/dist/components/shared/AllDayRow.d.ts.map +1 -1
  26. package/dist/components/shared/AllDayRow.js +21 -22
  27. package/dist/components/shared/EventChip.d.ts +4 -0
  28. package/dist/components/shared/EventChip.d.ts.map +1 -1
  29. package/dist/components/shared/EventChip.js +77 -69
  30. package/dist/components/shared/SelectionOverlay.d.ts +4 -0
  31. package/dist/components/shared/SelectionOverlay.d.ts.map +1 -1
  32. package/dist/components/shared/SelectionOverlay.js +38 -33
  33. package/dist/components/shared/SlotInteractionLayer.d.ts +5 -0
  34. package/dist/components/shared/SlotInteractionLayer.d.ts.map +1 -1
  35. package/dist/components/shared/SlotInteractionLayer.js +201 -176
  36. package/dist/components/shared/TimedEventLayer.d.ts +5 -2
  37. package/dist/components/shared/TimedEventLayer.d.ts.map +1 -1
  38. package/dist/components/shared/TimedEventLayer.js +57 -51
  39. package/dist/components/shared/useEventDrag.d.ts +36 -0
  40. package/dist/components/shared/useEventDrag.d.ts.map +1 -0
  41. package/dist/components/shared/useEventDrag.js +156 -0
  42. package/dist/components/shared/useLingeringValue.d.ts +7 -0
  43. package/dist/components/shared/useLingeringValue.d.ts.map +1 -0
  44. package/dist/components/shared/useLingeringValue.js +17 -0
  45. package/dist/components/shared/useTouchDrag.d.ts +38 -0
  46. package/dist/components/shared/useTouchDrag.d.ts.map +1 -0
  47. package/dist/components/shared/useTouchDrag.js +51 -0
  48. package/dist/index.d.ts +1 -1
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/lib/autoScroll.d.ts +30 -9
  51. package/dist/lib/autoScroll.d.ts.map +1 -1
  52. package/dist/lib/autoScroll.js +57 -51
  53. package/dist/types/calendar.d.ts +50 -0
  54. package/dist/types/calendar.d.ts.map +1 -1
  55. package/package.json +1 -1
@@ -0,0 +1,36 @@
1
+ import { RefObject } from 'react';
2
+ import { Temporal } from 'temporal-polyfill';
3
+ import { EventDrop, TimedCalendarEvent } from '../../types/calendar';
4
+ interface UseEventDragOptions {
5
+ /** Called with the new placement when the user drops an event somewhere new. */
6
+ onDrop?: (drop: EventDrop) => void;
7
+ gridRef: RefObject<HTMLElement | null>;
8
+ rootRef: RefObject<HTMLElement | null>;
9
+ /** The sticky gutter, so a drag past the left edge picks the first visible column. */
10
+ gutterRef: RefObject<HTMLElement | null>;
11
+ timeZone: string;
12
+ startHour: number;
13
+ endHour: number;
14
+ hourHeight: number;
15
+ snapDuration: number;
16
+ /** Maps a `data-event-column` id to the day it shows and, for resource columns, its resource. */
17
+ resolveTarget: (columnId: string) => {
18
+ date: Temporal.PlainDate;
19
+ resourceId?: string;
20
+ };
21
+ }
22
+ /**
23
+ * Drag-to-move for timed events. A mouse press on an event becomes a drag once
24
+ * the pointer moves a few pixels; a touch becomes one after a long press, so a
25
+ * swipe across events still scrolls the grid. The event then follows the
26
+ * pointer, snapped to `snapDuration`, across columns. Releasing it somewhere
27
+ * new calls `onDrop` and does nothing else: the caller decides whether to
28
+ * apply the move, ask for confirmation, or ignore it. Escape cancels a drag
29
+ * in progress.
30
+ */
31
+ export declare function useEventDrag(options: UseEventDragOptions): {
32
+ dragPreview: EventDrop | null;
33
+ startEventDrag: (event: TimedCalendarEvent, e: React.PointerEvent<HTMLElement>) => void;
34
+ };
35
+ export {};
36
+ //# sourceMappingURL=useEventDrag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEventDrag.d.ts","sourceRoot":"","sources":["../../../src/components/shared/useEventDrag.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAiBtE,UAAU,mBAAmB;IAC3B,gFAAgF;IAChF,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;IACnC,OAAO,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACvC,OAAO,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACvC,sFAAsF;IACtF,SAAS,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,iGAAiG;IACjG,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK;QACnC,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAC;QACzB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;CACH;AAkED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB;;4BAyK7C,kBAAkB,KAAK,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC;EAuEjE"}
@@ -0,0 +1,156 @@
1
+ import { useState as H, useRef as D, useLayoutEffect as y, useCallback as f, useEffect as C } from "react";
2
+ import { findVerticalScrollParent as A, createAutoScroller as N } from "../../lib/autoScroll.js";
3
+ import { minutesToZonedDateTime as Z } from "../../lib/time.js";
4
+ const U = 4, q = 400, G = 10;
5
+ function V(s, c, l) {
6
+ return c.toPlainDateTime().until(s.withTimeZone(l).toPlainDateTime(), {
7
+ largestUnit: "minutes"
8
+ }).total("minutes");
9
+ }
10
+ function k(s, c, { startHour: l, hourHeight: o }) {
11
+ const i = s.getBoundingClientRect();
12
+ return l * 60 + (c - i.top) * 60 / o;
13
+ }
14
+ function z() {
15
+ const s = (o) => {
16
+ o.detail !== 0 && (o.stopPropagation(), o.preventDefault(), c());
17
+ }, c = () => {
18
+ clearTimeout(l), document.removeEventListener("click", s, !0), document.removeEventListener("pointerdown", c, !0);
19
+ }, l = setTimeout(c, 1e3);
20
+ document.addEventListener("click", s, !0), document.addEventListener("pointerdown", c, !0);
21
+ }
22
+ function J(s) {
23
+ const [c, l] = H(null), o = D(null), i = D(s);
24
+ y(() => {
25
+ i.current = s;
26
+ });
27
+ const M = f((t) => {
28
+ const { gridRef: e, rootRef: n, gutterRef: a } = i.current, d = e.current?.querySelectorAll(
29
+ "[data-event-column]"
30
+ );
31
+ if (!d || d.length === 0) return null;
32
+ let m = t;
33
+ const v = a.current, u = n.current;
34
+ v && (m = Math.max(m, v.getBoundingClientRect().right)), u && (m = Math.min(m, u.getBoundingClientRect().right - 1));
35
+ let r = d[0];
36
+ for (const h of d) {
37
+ if (m < h.getBoundingClientRect().left) break;
38
+ r = h;
39
+ }
40
+ return r;
41
+ }, []), p = f(
42
+ (t, e) => {
43
+ const n = o.current;
44
+ if (!n?.started || n.cancelled) return;
45
+ const a = M(t), d = a?.dataset.eventColumn;
46
+ if (!a || d == null) return;
47
+ const { startHour: m, endHour: v, snapDuration: u, timeZone: r, resolveTarget: h } = i.current, x = k(a, e, i.current) - n.grabOffsetMin, O = Math.round(x / u) * u, S = Math.min(n.durationMin, u), _ = Math.min(
48
+ Math.max(O, m * 60 + S - n.durationMin),
49
+ v * 60 - S
50
+ ), { date: B, resourceId: Y } = h(d), w = Z(B, _, r), R = n.preview;
51
+ R && R.resourceId === (Y ?? n.event.resourceId) && R.startTime.equals(w) || (n.preview = {
52
+ event: n.event,
53
+ resourceId: Y ?? n.event.resourceId,
54
+ startTime: w,
55
+ endTime: w.add({ minutes: n.durationMin })
56
+ }, l(n.preview));
57
+ },
58
+ [M]
59
+ ), g = D(() => {
60
+ }), P = f(
61
+ (t) => {
62
+ const e = o.current;
63
+ if (!(!e || t.pointerId !== e.pointerId)) {
64
+ if (e.lastX = t.clientX, e.lastY = t.clientY, !e.started) {
65
+ const n = Math.hypot(
66
+ t.clientX - e.originX,
67
+ t.clientY - e.originY
68
+ );
69
+ if (e.isTouch) {
70
+ n > G && g.current();
71
+ return;
72
+ } else {
73
+ if (n < U) return;
74
+ e.started = !0;
75
+ }
76
+ }
77
+ p(t.clientX, t.clientY), e.cancelled || e.scroller?.ensure();
78
+ }
79
+ },
80
+ [p]
81
+ ), T = f((t) => {
82
+ const e = o.current;
83
+ if (!e || t.pointerId !== e.pointerId || (g.current(), !e.started) || (z(), t.type === "pointercancel")) return;
84
+ const n = e.preview;
85
+ if (e.cancelled || !n) return;
86
+ (n.resourceId !== e.event.resourceId || n.startTime.epochNanoseconds !== e.event.startTime.epochNanoseconds) && i.current.onDrop?.(n);
87
+ }, []), L = f((t) => {
88
+ const e = o.current;
89
+ t.key !== "Escape" || !e?.started || e.cancelled || (e.cancelled = !0, e.scroller?.stop(), l(null));
90
+ }, []), E = f((t) => t.preventDefault(), []);
91
+ y(() => {
92
+ g.current = () => {
93
+ const t = o.current;
94
+ t?.longPressTimer != null && clearTimeout(t.longPressTimer), t?.scroller?.stop(), o.current = null, l(null), document.removeEventListener("pointermove", P), document.removeEventListener("pointerup", T), document.removeEventListener("pointercancel", T), document.removeEventListener("keydown", L), document.removeEventListener("selectstart", E), document.removeEventListener("contextmenu", E);
95
+ };
96
+ }), C(() => () => g.current(), []);
97
+ const I = s.onDrop != null, { rootRef: X } = s;
98
+ C(() => {
99
+ const t = X.current;
100
+ if (!I || !t) return;
101
+ const e = (n) => {
102
+ o.current?.started && n.preventDefault();
103
+ };
104
+ return t.addEventListener("touchmove", e, { passive: !1 }), () => t.removeEventListener("touchmove", e);
105
+ }, [I, X]);
106
+ const b = f(
107
+ (t, e) => {
108
+ if (!e.isPrimary || e.button !== 0 || !i.current.onDrop) return;
109
+ const n = e.currentTarget.closest(
110
+ "[data-event-column]"
111
+ ), a = n?.dataset.eventColumn;
112
+ if (!n || a == null) return;
113
+ g.current();
114
+ const { timeZone: d, resolveTarget: m } = i.current, { date: v } = m(a), u = e.pointerType !== "mouse", r = {
115
+ event: t,
116
+ pointerId: e.pointerId,
117
+ isTouch: u,
118
+ longPressTimer: null,
119
+ originX: e.clientX,
120
+ originY: e.clientY,
121
+ grabOffsetMin: k(n, e.clientY, i.current) - V(t.startTime, v, d),
122
+ durationMin: t.startTime.until(t.endTime).total("minutes"),
123
+ started: !1,
124
+ cancelled: !1,
125
+ preview: null,
126
+ lastX: e.clientX,
127
+ lastY: e.clientY,
128
+ scroller: null,
129
+ scrollParent: A(n)
130
+ };
131
+ r.scroller = N({
132
+ getPointerY: () => r.lastY,
133
+ getScrollParent: () => r.scrollParent,
134
+ horizontal: {
135
+ getPointerX: () => r.lastX,
136
+ // The sticky gutter covers the first column while scrolled
137
+ getViewportLeft: () => i.current.gutterRef.current?.getBoundingClientRect().right
138
+ },
139
+ onScroll: () => p(r.lastX, r.lastY)
140
+ }), u && (r.longPressTimer = setTimeout(() => {
141
+ r.longPressTimer = null, r.started = !0, window.getSelection()?.removeAllRanges(), p(r.lastX, r.lastY);
142
+ }, q)), o.current = r, document.addEventListener("pointermove", P), document.addEventListener("pointerup", T), document.addEventListener("pointercancel", T), document.addEventListener("keydown", L), document.addEventListener("selectstart", E), u && document.addEventListener("contextmenu", E);
143
+ },
144
+ [
145
+ P,
146
+ T,
147
+ L,
148
+ E,
149
+ p
150
+ ]
151
+ );
152
+ return { dragPreview: c, startEventDrag: b };
153
+ }
154
+ export {
155
+ J as useEventDrag
156
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Returns `value`, or for `lingerMs` after it is cleared, its last non-null
3
+ * value. Keeps an overlay mounted briefly after clearing so a popover's close
4
+ * transition doesn't lose its reference element.
5
+ */
6
+ export declare function useLingeringValue<T>(value: T | null | undefined, lingerMs: number): T | null;
7
+ //# sourceMappingURL=useLingeringValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLingeringValue.d.ts","sourceRoot":"","sources":["../../../src/components/shared/useLingeringValue.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EAC3B,QAAQ,EAAE,MAAM,GACf,CAAC,GAAG,IAAI,CAyBV"}
@@ -0,0 +1,17 @@
1
+ import { useRef as l, useState as f, useEffect as o } from "react";
2
+ function m(e, r) {
3
+ const n = l(null), t = l(null), [c, u] = f(null);
4
+ return o(() => {
5
+ if (e)
6
+ t.current !== null && (clearTimeout(t.current), t.current = null), n.current = e;
7
+ else if (n.current && r > 0) {
8
+ const s = n.current;
9
+ n.current = null, u(s), t.current = setTimeout(() => {
10
+ t.current = null, u(null);
11
+ }, r);
12
+ }
13
+ }, [e, r]), e ?? c;
14
+ }
15
+ export {
16
+ m as useLingeringValue
17
+ };
@@ -0,0 +1,38 @@
1
+ import { RefObject } from 'react';
2
+ /** How long (ms) a touch must rest before it can drag. */
3
+ export declare const LONG_PRESS_MS = 400;
4
+ /** How far (px) a touch can wander during the long press before it counts as a scroll. */
5
+ export declare const TOUCH_SLOP_PX = 10;
6
+ /**
7
+ * Style for an element a long press drags: keeps the press from selecting
8
+ * text or opening the iOS callout. Safari ignores `user-select` without its
9
+ * `-webkit-` prefix.
10
+ */
11
+ export declare const TOUCH_DRAG_STYLE: {
12
+ readonly WebkitTouchCallout: "none";
13
+ readonly WebkitUserSelect: "none";
14
+ readonly userSelect: "none";
15
+ };
16
+ export interface TouchDragHandlers {
17
+ /** The long press completed. Return `false` to not drag after all. */
18
+ start: (clientX: number, clientY: number) => boolean | void;
19
+ move: (clientX: number, clientY: number) => void;
20
+ end: (clientX: number, clientY: number) => void;
21
+ /** The browser took the touch back, for example to scroll. */
22
+ cancel: () => void;
23
+ }
24
+ /**
25
+ * Long-press drags for touch and pen. Call the returned `startTouchDrag` from
26
+ * a pointerdown: it ignores the mouse and returns false. For a touch it
27
+ * returns true and waits `LONG_PRESS_MS` before calling `start`. Moving more
28
+ * than `TOUCH_SLOP_PX` before then leaves the touch to scroll, and lifting it
29
+ * is a tap, which the browser reports as emulated mouse events and a click,
30
+ * as it did before. Once a drag starts, the finger no longer scrolls, and no
31
+ * emulated mouse events or click follow the touch.
32
+ *
33
+ * `containerRef` must contain every element whose pointerdown can start a
34
+ * drag: it holds the touch listeners, which have to be in place before a
35
+ * touch begins to be able to stop it scrolling.
36
+ */
37
+ export declare function useTouchDrag(containerRef: RefObject<HTMLElement | null>, enabled: boolean): (e: React.PointerEvent, handlers: TouchDragHandlers) => boolean;
38
+ //# sourceMappingURL=useTouchDrag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTouchDrag.d.ts","sourceRoot":"","sources":["../../../src/components/shared/useTouchDrag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvE,0DAA0D;AAC1D,eAAO,MAAM,aAAa,MAAM,CAAC;AAEjC,0FAA0F;AAC1F,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC;;;;GAIG;AACH,eAAO,MAAM,gBAAgB;;;;CAInB,CAAC;AAEX,MAAM,WAAW,iBAAiB;IAChC,sEAAsE;IACtE,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,GAAG,IAAI,CAAC;IAC5D,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,8DAA8D;IAC9D,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAC1B,YAAY,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAC3C,OAAO,EAAE,OAAO,OA6BV,KAAK,CAAC,YAAY,YAAY,iBAAiB,KAAG,OAAO,CAmEhE"}
@@ -0,0 +1,51 @@
1
+ import { useRef as L, useEffect as S, useCallback as T } from "react";
2
+ const h = 400, D = 10, k = {
3
+ WebkitTouchCallout: "none",
4
+ WebkitUserSelect: "none",
5
+ userSelect: "none"
6
+ };
7
+ function y(d, f) {
8
+ const o = L(!1), i = L(() => {
9
+ });
10
+ return S(() => {
11
+ const e = d.current;
12
+ if (!f || !e) return;
13
+ const n = (r) => {
14
+ o.current && r.preventDefault();
15
+ }, c = (r) => {
16
+ o.current && (o.current = !1, r.preventDefault());
17
+ };
18
+ return e.addEventListener("touchmove", n, { passive: !1 }), e.addEventListener("touchend", c, { passive: !1 }), () => {
19
+ e.removeEventListener("touchmove", n), e.removeEventListener("touchend", c);
20
+ };
21
+ }, [d, f]), S(() => () => i.current(), []), T(
22
+ (e, n) => {
23
+ if (e.pointerType === "mouse" || !e.isPrimary) return !1;
24
+ i.current();
25
+ const { pointerId: c } = e, r = e.clientX, p = e.clientY;
26
+ let s = r, u = p, m = !1;
27
+ const E = (t) => {
28
+ t.pointerId === c && (s = t.clientX, u = t.clientY, m ? n.move(s, u) : Math.hypot(s - r, u - p) > D && v());
29
+ }, l = (t) => {
30
+ t.pointerId === c && (v(), m && (t.type === "pointercancel" ? (o.current = !1, n.cancel()) : n.end(s, u)));
31
+ }, a = (t) => t.preventDefault(), g = setTimeout(() => {
32
+ if (n.start(s, u) === !1) {
33
+ v();
34
+ return;
35
+ }
36
+ m = !0, o.current = !0, window.getSelection()?.removeAllRanges();
37
+ }, h), v = () => {
38
+ clearTimeout(g), document.removeEventListener("pointermove", E), document.removeEventListener("pointerup", l), document.removeEventListener("pointercancel", l), document.removeEventListener("contextmenu", a), document.removeEventListener("selectstart", a), i.current = () => {
39
+ };
40
+ };
41
+ return i.current = v, document.addEventListener("pointermove", E), document.addEventListener("pointerup", l), document.addEventListener("pointercancel", l), document.addEventListener("contextmenu", a), document.addEventListener("selectstart", a), !0;
42
+ },
43
+ []
44
+ );
45
+ }
46
+ export {
47
+ h as LONG_PRESS_MS,
48
+ k as TOUCH_DRAG_STYLE,
49
+ D as TOUCH_SLOP_PX,
50
+ y as useTouchDrag
51
+ };
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { MonthView } from './components/month-view';
5
5
  export { resourceGridViewDefaults } from './components/resource-grid-view';
6
6
  export { dayGridViewDefaults } from './components/day-grid-view';
7
7
  export { monthViewDefaults } from './components/month-view';
8
- export type { CalendarResource, CalendarEvent, TimedCalendarEvent, AllDayCalendarEvent, TimeSlot, AvailabilityRange, BackgroundEvent, TimeAxisConfig, ResourceGridViewProps, ResourceGridViewClassNames, GridViewClassNames, DayGridViewProps, DayGridViewClassNames, DayGridSelectedRange, PositionedEvent, OverflowClickInfo, OverflowPopoverRenderProps, SelectedRange, SelectionAppearance, SelectionEventData, EventLayout, MonthViewProps, MonthViewClassNames, MonthSelectedRange, MonthOverflowClickInfo, MonthOverflowPopoverRenderProps, } from './types/calendar';
8
+ export type { CalendarResource, CalendarEvent, TimedCalendarEvent, AllDayCalendarEvent, TimeSlot, AvailabilityRange, BackgroundEvent, TimeAxisConfig, ResourceGridViewProps, ResourceGridViewClassNames, GridViewClassNames, DayGridViewProps, DayGridViewClassNames, DayGridSelectedRange, PositionedEvent, OverflowClickInfo, OverflowPopoverRenderProps, SelectedRange, EventDrop, SelectionAppearance, SelectionEventData, EventLayout, MonthViewProps, MonthViewClassNames, MonthSelectedRange, MonthOverflowClickInfo, MonthOverflowPopoverRenderProps, } from './types/calendar';
9
9
  export { cn } from './lib/utils';
10
10
  export { timedEvent, allDayEvent } from './lib/events';
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D,YAAY,EACV,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,qBAAqB,EACrB,0BA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AAa,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC"}
@@ -2,6 +2,16 @@
2
2
  export declare const AUTO_SCROLL_EDGE_PX = 48;
3
3
  /** Peak auto-scroll speed while the pointer is at or past an edge. */
4
4
  export declare const AUTO_SCROLL_MAX_PX_PER_SECOND = 400;
5
+ /**
6
+ * Sideways edge zone, in px. Narrower than the vertical one, which would
7
+ * take a quarter of a phone's width.
8
+ */
9
+ export declare const AUTO_SCROLL_HORIZONTAL_EDGE_PX = 32;
10
+ /**
11
+ * Peak sideways speed. Slower than vertical, since one column can be most of
12
+ * the viewport and is easy to overshoot.
13
+ */
14
+ export declare const AUTO_SCROLL_HORIZONTAL_MAX_PX_PER_SECOND = 250;
5
15
  /**
6
16
  * Nearest ancestor that scrolls vertically (overflow-y auto/scroll/overlay).
7
17
  * The calendar root is `overflow-auto`, so this is the grid's own scroller.
@@ -16,19 +26,30 @@ export declare function findVerticalScrollParent(el: HTMLElement): HTMLElement |
16
26
  */
17
27
  export declare function computeAutoScrollIntensity(pointerY: number, viewportTop: number, viewportBottom: number, edgePx?: number): number;
18
28
  /**
19
- * Scroll `scrollParent` by `intensity * maxPxPerSecond * deltaSeconds`.
20
- * Returns the actual delta applied after clamping to the scroll range.
29
+ * Scroll `scrollParent` along `axis` by
30
+ * `intensity * maxPxPerSecond * deltaSeconds`. Returns the actual delta
31
+ * applied after clamping to the scroll range.
21
32
  */
22
- export declare function applyVerticalAutoScroll(scrollParent: HTMLElement, intensity: number, deltaSeconds: number, maxPxPerSecond?: number): number;
23
- export interface VerticalAutoScroller {
33
+ export declare function applyAutoScroll(scrollParent: HTMLElement, axis: 'x' | 'y', intensity: number, deltaSeconds: number, maxPxPerSecond?: number): number;
34
+ export interface AutoScroller {
24
35
  /** Start the rAF loop if it isn't already running. */
25
36
  ensure: () => void;
26
37
  /** Cancel the rAF loop. Safe to call more than once. */
27
38
  stop: () => void;
28
39
  }
29
- interface CreateVerticalAutoScrollerOptions {
30
- getPointerY: () => number;
40
+ interface CreateAutoScrollerOptions {
41
+ /** Omit to scroll sideways only. */
42
+ getPointerY?: () => number;
31
43
  getScrollParent: () => HTMLElement | null;
44
+ /** Also scroll sideways when the pointer nears the left or right edge. */
45
+ horizontal?: {
46
+ getPointerX: () => number;
47
+ /**
48
+ * Left edge of the visible area, such as the right edge of a sticky
49
+ * gutter that covers the first column. Default: the scroller's left edge.
50
+ */
51
+ getViewportLeft?: () => number | undefined;
52
+ };
32
53
  /** Called after the scroller actually moves, so the caller can remap the pointer. */
33
54
  onScroll: () => void;
34
55
  raf?: typeof requestAnimationFrame;
@@ -36,9 +57,9 @@ interface CreateVerticalAutoScrollerOptions {
36
57
  }
37
58
  /**
38
59
  * rAF loop that auto-scrolls while the pointer sits in an edge zone. The
39
- * loop stops on its own when intensity hits 0 or the scroller can't move
40
- * further; call `ensure()` again to resume.
60
+ * loop stops on its own when the pointer leaves the edge zones or the
61
+ * scroller can't move further; call `ensure()` again to resume.
41
62
  */
42
- export declare function createVerticalAutoScroller({ getPointerY, getScrollParent, onScroll, raf, cancelRaf, }: CreateVerticalAutoScrollerOptions): VerticalAutoScroller;
63
+ export declare function createAutoScroller({ getPointerY, getScrollParent, horizontal, onScroll, raf, cancelRaf, }: CreateAutoScrollerOptions): AutoScroller;
43
64
  export {};
44
65
  //# sourceMappingURL=autoScroll.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"autoScroll.d.ts","sourceRoot":"","sources":["../../src/lib/autoScroll.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC,sEAAsE;AACtE,eAAO,MAAM,6BAA6B,MAAM,CAAC;AAMjD;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,CAS5E;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,MAAM,EAChB,WAAW,E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MAAM,EACnB,cAAc,EAAE,MAAM,EACtB,MAAM,GAAE,MAA4B,GACnC,MAAM,CAiBR;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,WAAW,EACzB,IAAI,EAAE,GAAG,GAAG,GAAG,EACf,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,cAAc,GAAE,MAE4B,GAC3C,MAAM,CAeR;AAED,MAAM,WAAW,YAAY;IAC3B,sDAAsD;IACtD,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,wDAAwD;IACxD,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB;AAED,UAAU,yBAAyB;IACjC,oCAAoC;IACpC,WAAW,CAAC,EAAE,MAAM,MAAM,CAAC;IAC3B,eAAe,EAAE,MAAM,WAAW,GAAG,IAAI,CAAC;IAC1C,0EAA0E;IAC1E,UAAU,CAAC,EAAE;QACX,WAAW,EAAE,MAAM,MAAM,CAAC;QAC1B;;;WAGG;QACH,eAAe,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;KAC5C,CAAC;IACF,qFAAqF;IACrF,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,GAAG,CAAC,EAAE,OAAO,qBAAqB,CAAC;IACnC,SAAS,CAAC,EAAE,OAAO,oBAAoB,CAAC;CACzC;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,WAAW,EACX,eAAe,EACf,UAAU,EACV,QAAQ,EACR,GAA2B,EAC3B,SAAgC,GACjC,EAAE,yBAAyB,GAAG,YAAY,CA4D1C"}
@@ -1,78 +1,84 @@
1
- const O = 48, d = 400;
2
- function h(n) {
3
- return n === "auto" || n === "scroll" || n === "overlay";
1
+ const C = 48, T = 400, d = 32, h = 250;
2
+ function a(t) {
3
+ return t === "auto" || t === "scroll" || t === "overlay";
4
4
  }
5
- function E(n) {
6
- let e = n.parentElement;
7
- for (; e; ) {
8
- if (h(getComputedStyle(e).overflowY))
9
- return e;
10
- e = e.parentElement;
5
+ function p(t) {
6
+ let n = t.parentElement;
7
+ for (; n; ) {
8
+ if (a(getComputedStyle(n).overflowY))
9
+ return n;
10
+ n = n.parentElement;
11
11
  }
12
12
  return null;
13
13
  }
14
- function S(n, e, o, c = 48) {
15
- const u = o - e;
16
- if (u <= 0) return 0;
17
- const t = Math.min(c, u / 2);
18
- if (t <= 0) return 0;
19
- const l = o - n, r = n - e;
20
- return l < t && l <= r ? Math.min(1, (t - l) / t) : r < t ? -Math.min(1, (t - r) / t) : 0;
14
+ function S(t, n, o, u = 48) {
15
+ const c = o - n;
16
+ if (c <= 0) return 0;
17
+ const r = Math.min(u, c / 2);
18
+ if (r <= 0) return 0;
19
+ const l = o - t, e = t - n;
20
+ return l < r && l <= e ? Math.min(1, (r - l) / r) : e < r ? -Math.min(1, (r - e) / r) : 0;
21
21
  }
22
- function p(n, e, o, c = 400) {
23
- if (e === 0 || o <= 0) return 0;
24
- const u = e * c * o, t = Math.max(
22
+ function m(t, n, o, u, c = n === "y" ? 400 : 250) {
23
+ if (o === 0 || u <= 0) return 0;
24
+ const r = o * c * u, l = Math.max(
25
25
  0,
26
- n.scrollHeight - n.clientHeight
27
- ), l = n.scrollTop, r = Math.min(t, Math.max(0, l + u));
28
- return n.scrollTop = r, r - l;
26
+ n === "y" ? t.scrollHeight - t.clientHeight : t.scrollWidth - t.clientWidth
27
+ ), e = n === "y" ? "scrollTop" : "scrollLeft", i = t[e], _ = Math.min(l, Math.max(0, i + r));
28
+ return t[e] = _, _ - i;
29
29
  }
30
30
  function M({
31
- getPointerY: n,
32
- getScrollParent: e,
33
- onScroll: o,
31
+ getPointerY: t,
32
+ getScrollParent: n,
33
+ horizontal: o,
34
+ onScroll: u,
34
35
  raf: c = requestAnimationFrame,
35
- cancelRaf: u = cancelAnimationFrame
36
+ cancelRaf: r = cancelAnimationFrame
36
37
  }) {
37
- let t = null, l = null, r = !1;
38
- const s = (a) => {
39
- if (r) return;
40
- t = null;
41
- const i = e();
42
- if (!i) {
43
- l = null;
38
+ let l = null, e = null, i = !1;
39
+ const _ = (f) => {
40
+ if (i) return;
41
+ l = null;
42
+ const s = n();
43
+ if (!s) {
44
+ e = null;
44
45
  return;
45
46
  }
46
- const f = i.getBoundingClientRect(), m = S(
47
- n(),
48
- f.top,
49
- f.bottom
50
- );
51
- if (m === 0) {
52
- l = null;
47
+ const O = s.getBoundingClientRect(), L = t ? S(t(), O.top, O.bottom) : 0, A = o ? S(
48
+ o.getPointerX(),
49
+ o.getViewportLeft?.() ?? O.left,
50
+ O.right,
51
+ 32
52
+ ) : 0;
53
+ if (A === 0 && L === 0) {
54
+ e = null;
53
55
  return;
54
56
  }
55
- const _ = l == null ? 1 / 60 : Math.min(0.05, (a - l) / 1e3);
56
- if (l = a, p(i, m, _) === 0) {
57
- l = null;
57
+ const E = e == null ? 1 / 60 : Math.min(0.05, (f - e) / 1e3);
58
+ e = f;
59
+ const R = m(s, "y", L, E);
60
+ if (m(s, "x", A, E) === 0 && R === 0) {
61
+ e = null;
58
62
  return;
59
63
  }
60
- o(), t = c(s);
64
+ u(), l = c(_);
61
65
  };
62
66
  return {
63
67
  ensure: () => {
64
- r || t != null || (t = c(s));
68
+ i || l != null || (l = c(_));
65
69
  },
66
70
  stop: () => {
67
- r = !0, t != null && (u(t), t = null), l = null;
71
+ i = !0, l != null && (r(l), l = null), e = null;
68
72
  }
69
73
  };
70
74
  }
71
75
  export {
72
- O as AUTO_SCROLL_EDGE_PX,
73
- d as AUTO_SCROLL_MAX_PX_PER_SECOND,
74
- p as applyVerticalAutoScroll,
76
+ C as AUTO_SCROLL_EDGE_PX,
77
+ d as AUTO_SCROLL_HORIZONTAL_EDGE_PX,
78
+ h as AUTO_SCROLL_HORIZONTAL_MAX_PX_PER_SECOND,
79
+ T as AUTO_SCROLL_MAX_PX_PER_SECOND,
80
+ m as applyAutoScroll,
75
81
  S as computeAutoScrollIntensity,
76
- M as createVerticalAutoScroller,
77
- E as findVerticalScrollParent
82
+ M as createAutoScroller,
83
+ p as findVerticalScrollParent
78
84
  };
@@ -27,6 +27,11 @@ interface BaseCalendarEvent {
27
27
  * Default: true.
28
28
  */
29
29
  interactive?: boolean;
30
+ /**
31
+ * Set to `false` to keep an interactive event from being dragged when the
32
+ * view has `onEventDrop`. Default: true.
33
+ */
34
+ draggable?: boolean;
30
35
  /**
31
36
  * `'outline'` draws the event as an outline in its color, with no fill or
32
37
  * color bar, as calendar apps draw invitations awaiting a reply. Default:
@@ -63,6 +68,19 @@ export interface BackgroundEvent {
63
68
  /** Class name applied to the positioned block. */
64
69
  className?: string;
65
70
  }
71
+ /**
72
+ * Where the user dropped a dragged event. The event itself is unchanged:
73
+ * apply the move by updating your events.
74
+ */
75
+ export interface EventDrop {
76
+ /** The event as it was before the drag. */
77
+ event: TimedCalendarEvent;
78
+ /** The resource it was dropped on. In DayGridView, the event's own resource. */
79
+ resourceId: string;
80
+ startTime: Temporal.ZonedDateTime;
81
+ /** The new start plus the event's original duration. */
82
+ endTime: Temporal.ZonedDateTime;
83
+ }
66
84
  export interface AvailabilityRange {
67
85
  startTime: Temporal.ZonedDateTime;
68
86
  endTime: Temporal.ZonedDateTime;
@@ -99,6 +117,8 @@ export interface GridViewClassNames {
99
117
  event?: string;
100
118
  eventSelected?: string;
101
119
  eventOutline?: string;
120
+ /** The event being dragged, or awaiting confirmation of a drop, in its original place. */
121
+ eventDragSource?: string;
102
122
  eventColorBar?: string;
103
123
  eventTitle?: string;
104
124
  eventTime?: string;
@@ -196,6 +216,21 @@ export interface ResourceGridViewProps {
196
216
  selectionRef?: Ref<HTMLDivElement>;
197
217
  /** How long (ms) the selection overlay remains in DOM after clearing, to allow popover close transitions. Default: 0 */
198
218
  selectionLingerMs?: number;
219
+ /**
220
+ * Called when the user drags a timed event to a new time or resource and releases
221
+ * it. Setting it makes interactive timed events draggable. The grid doesn't
222
+ * move the event: store the drop in `pendingDrop` to show it while you ask
223
+ * for confirmation, then update `events` to apply it.
224
+ */
225
+ onEventDrop?: (drop: EventDrop) => void;
226
+ /**
227
+ * A drop awaiting confirmation. The grid draws the event at its new place
228
+ * and dims it in its old one. Clear it to cancel the move or after applying
229
+ * it. It lingers, invisible, for `selectionLingerMs` after clearing.
230
+ */
231
+ pendingDrop?: EventDrop | null;
232
+ /** Ref attached to the event drawn at `pendingDrop`, for positioning a confirmation popover. */
233
+ pendingDropRef?: Ref<HTMLDivElement>;
199
234
  selectedEventId?: string | null;
200
235
  selectedEventRef?: Ref<HTMLDivElement>;
201
236
  renderCorner?: (props: {
@@ -296,6 +331,21 @@ export interface DayGridViewProps {
296
331
  dragPreviewAppearance?: SelectionAppearance;
297
332
  selectionRef?: Ref<HTMLDivElement>;
298
333
  selectionLingerMs?: number;
334
+ /**
335
+ * Called when the user drags a timed event to a new time or day and releases
336
+ * it. Setting it makes interactive timed events draggable. The grid doesn't
337
+ * move the event: store the drop in `pendingDrop` to show it while you ask
338
+ * for confirmation, then update `events` to apply it.
339
+ */
340
+ onEventDrop?: (drop: EventDrop) => void;
341
+ /**
342
+ * A drop awaiting confirmation. The grid draws the event at its new place
343
+ * and dims it in its old one. Clear it to cancel the move or after applying
344
+ * it. It lingers, invisible, for `selectionLingerMs` after clearing.
345
+ */
346
+ pendingDrop?: EventDrop | null;
347
+ /** Ref attached to the event drawn at `pendingDrop`, for positioning a confirmation popover. */
348
+ pendingDropRef?: Ref<HTMLDivElement>;
299
349
  selectedEventId?: string | null;
300
350
  selectedEventRef?: Ref<HTMLDivElement>;
301
351
  renderCorner?: (props: {