@super-calendar/core 2.9.0 → 2.10.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 CHANGED
@@ -53,6 +53,10 @@ import { clampMoveStartMinutes } from "@super-calendar/core";
53
53
  const startMinutes = clampMoveStartMinutes(rawStartMinutes, minHour, maxHour, snapMinutes);
54
54
  ```
55
55
 
56
+ Use `resolveDraggedBounds` to commit a move or resize. Equal start and end deltas
57
+ move the event while preserving elapsed duration, including across daylight
58
+ saving changes. For a resize, pass zero for the edge you want to keep fixed.
59
+
56
60
  ## Documentation
57
61
 
58
62
  See the [full documentation](https://super-calendar.afonsojramos.me) and the [API reference](https://super-calendar.afonsojramos.me/reference/api).
package/dist/index.d.mts CHANGED
@@ -416,7 +416,8 @@ declare function shiftMinutes(date: Date, minutes: number): Date;
416
416
  /**
417
417
  * Resolve a committed drag into the event's new bounds: `start` shifts by
418
418
  * `deltaStartMinutes`, `end` by `deltaEndMinutes` (a move passes the same delta
419
- * to both; a resize passes 0 for the start). Returns `null` only when the change
419
+ * to both and preserves elapsed duration, including across DST; a resize passes
420
+ * 0 for the unchanged edge). Returns `null` only when the change
420
421
  * would *shrink* the event below one `snapMinutes` step, so a resize can't commit
421
422
  * a degenerate duration; a pure move (both deltas equal) keeps its duration and is
422
423
  * never rejected, even for an already sub-step event. Pure, so the commit path is
package/dist/index.d.ts CHANGED
@@ -416,7 +416,8 @@ declare function shiftMinutes(date: Date, minutes: number): Date;
416
416
  /**
417
417
  * Resolve a committed drag into the event's new bounds: `start` shifts by
418
418
  * `deltaStartMinutes`, `end` by `deltaEndMinutes` (a move passes the same delta
419
- * to both; a resize passes 0 for the start). Returns `null` only when the change
419
+ * to both and preserves elapsed duration, including across DST; a resize passes
420
+ * 0 for the unchanged edge). Returns `null` only when the change
420
421
  * would *shrink* the event below one `snapMinutes` step, so a resize can't commit
421
422
  * a degenerate duration; a pure move (both deltas equal) keeps its duration and is
422
423
  * never rejected, even for an already sub-step event. Pure, so the commit path is
package/dist/index.js CHANGED
@@ -330,6 +330,7 @@ function clampMoveStartMinutes(startMinutes, minHour, maxHour, snapMinutes) {
330
330
  }
331
331
  /** A copy of `date` shifted by `minutes` (may be negative). */
332
332
  function shiftMinutes(date, minutes) {
333
+ "worklet";
333
334
  const next = new Date(date);
334
335
  next.setMinutes(next.getMinutes() + minutes);
335
336
  return next;
@@ -337,7 +338,8 @@ function shiftMinutes(date, minutes) {
337
338
  /**
338
339
  * Resolve a committed drag into the event's new bounds: `start` shifts by
339
340
  * `deltaStartMinutes`, `end` by `deltaEndMinutes` (a move passes the same delta
340
- * to both; a resize passes 0 for the start). Returns `null` only when the change
341
+ * to both and preserves elapsed duration, including across DST; a resize passes
342
+ * 0 for the unchanged edge). Returns `null` only when the change
341
343
  * would *shrink* the event below one `snapMinutes` step, so a resize can't commit
342
344
  * a degenerate duration; a pure move (both deltas equal) keeps its duration and is
343
345
  * never rejected, even for an already sub-step event. Pure, so the commit path is
@@ -345,8 +347,8 @@ function shiftMinutes(date, minutes) {
345
347
  */
346
348
  function resolveDraggedBounds(start, end, deltaStartMinutes, deltaEndMinutes, snapMinutes) {
347
349
  const nextStart = shiftMinutes(start, deltaStartMinutes);
348
- const nextEnd = shiftMinutes(end, deltaEndMinutes);
349
350
  const oldDuration = end.getTime() - start.getTime();
351
+ const nextEnd = deltaStartMinutes === deltaEndMinutes ? new Date(nextStart.getTime() + oldDuration) : shiftMinutes(end, deltaEndMinutes);
350
352
  const newDuration = nextEnd.getTime() - nextStart.getTime();
351
353
  if (newDuration < snapMinutes * 6e4 && newDuration < oldDuration) return null;
352
354
  return {
package/dist/index.mjs CHANGED
@@ -329,6 +329,7 @@ function clampMoveStartMinutes(startMinutes, minHour, maxHour, snapMinutes) {
329
329
  }
330
330
  /** A copy of `date` shifted by `minutes` (may be negative). */
331
331
  function shiftMinutes(date, minutes) {
332
+ "worklet";
332
333
  const next = new Date(date);
333
334
  next.setMinutes(next.getMinutes() + minutes);
334
335
  return next;
@@ -336,7 +337,8 @@ function shiftMinutes(date, minutes) {
336
337
  /**
337
338
  * Resolve a committed drag into the event's new bounds: `start` shifts by
338
339
  * `deltaStartMinutes`, `end` by `deltaEndMinutes` (a move passes the same delta
339
- * to both; a resize passes 0 for the start). Returns `null` only when the change
340
+ * to both and preserves elapsed duration, including across DST; a resize passes
341
+ * 0 for the unchanged edge). Returns `null` only when the change
340
342
  * would *shrink* the event below one `snapMinutes` step, so a resize can't commit
341
343
  * a degenerate duration; a pure move (both deltas equal) keeps its duration and is
342
344
  * never rejected, even for an already sub-step event. Pure, so the commit path is
@@ -344,8 +346,8 @@ function shiftMinutes(date, minutes) {
344
346
  */
345
347
  function resolveDraggedBounds(start, end, deltaStartMinutes, deltaEndMinutes, snapMinutes) {
346
348
  const nextStart = shiftMinutes(start, deltaStartMinutes);
347
- const nextEnd = shiftMinutes(end, deltaEndMinutes);
348
349
  const oldDuration = end.getTime() - start.getTime();
350
+ const nextEnd = deltaStartMinutes === deltaEndMinutes ? new Date(nextStart.getTime() + oldDuration) : shiftMinutes(end, deltaEndMinutes);
349
351
  const newDuration = nextEnd.getTime() - nextStart.getTime();
350
352
  if (newDuration < snapMinutes * 6e4 && newDuration < oldDuration) return null;
351
353
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-calendar/core",
3
- "version": "2.9.0",
3
+ "version": "2.10.0",
4
4
  "description": "Render-agnostic core for super-calendar: date math, selection model, event layout, the month-grid builder, headless hooks, and neutral theme tokens. No renderer.",
5
5
  "keywords": [
6
6
  "calendar",
package/src/utils/drag.ts CHANGED
@@ -79,6 +79,7 @@ export function clampMoveStartMinutes(
79
79
 
80
80
  /** A copy of `date` shifted by `minutes` (may be negative). */
81
81
  export function shiftMinutes(date: Date, minutes: number): Date {
82
+ "worklet";
82
83
  const next = new Date(date);
83
84
  next.setMinutes(next.getMinutes() + minutes);
84
85
  return next;
@@ -87,7 +88,8 @@ export function shiftMinutes(date: Date, minutes: number): Date {
87
88
  /**
88
89
  * Resolve a committed drag into the event's new bounds: `start` shifts by
89
90
  * `deltaStartMinutes`, `end` by `deltaEndMinutes` (a move passes the same delta
90
- * to both; a resize passes 0 for the start). Returns `null` only when the change
91
+ * to both and preserves elapsed duration, including across DST; a resize passes
92
+ * 0 for the unchanged edge). Returns `null` only when the change
91
93
  * would *shrink* the event below one `snapMinutes` step, so a resize can't commit
92
94
  * a degenerate duration; a pure move (both deltas equal) keeps its duration and is
93
95
  * never rejected, even for an already sub-step event. Pure, so the commit path is
@@ -101,8 +103,11 @@ export function resolveDraggedBounds(
101
103
  snapMinutes: number,
102
104
  ): { start: Date; end: Date } | null {
103
105
  const nextStart = shiftMinutes(start, deltaStartMinutes);
104
- const nextEnd = shiftMinutes(end, deltaEndMinutes);
105
106
  const oldDuration = end.getTime() - start.getTime();
107
+ const nextEnd =
108
+ deltaStartMinutes === deltaEndMinutes
109
+ ? new Date(nextStart.getTime() + oldDuration)
110
+ : shiftMinutes(end, deltaEndMinutes);
106
111
  const newDuration = nextEnd.getTime() - nextStart.getTime();
107
112
  // Reject only a shrink past one step — never a move, which preserves duration.
108
113
  if (newDuration < snapMinutes * 60_000 && newDuration < oldDuration) return null;