@moltenship/calendar-dnd 1.0.0-rc.1 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { CalendarAnnouncer, CalendarDraft, CalendarEventPlacement, CalendarEventProposal, CalendarPolicyResult, CalendarProposalDetail, CalendarTransactionResult, EventId, EventSnapshot, NormalizedCalendarEvent, ResourceId, TimeGridColumn } from "@moltenship/calendar-core";
2
2
  import { WallTimeSnapOptions } from "@moltenship/calendar-temporal";
3
3
  import { RefCallback } from "react";
4
- //#region src/attach-calendar-pointer.d.ts
5
4
  interface CalendarPointerOptions<TEvent, TEventId extends EventId, TResourceId extends ResourceId> {
6
5
  /** Events as rendered, pending changes included; resolves `data-event-id`. */
7
6
  readonly events: EventSnapshot<TEvent, TEventId, TResourceId>;
@@ -22,10 +21,12 @@ interface CalendarPointerOptions<TEvent, TEventId extends EventId, TResourceId e
22
21
  readonly announcer?: CalendarAnnouncer;
23
22
  /**
24
23
  * Asks the root's policies about the proposal a drop would make, so the preview shows whether
25
- * it would be saved: pass `actions.checkEventChange`. Preview segments get `data-invalid` when
26
- * a policy rejects it and `data-warning` when one flags it.
24
+ * it would be saved: pass `actions.checkEventChange`. It gets the detail the drop will propose
25
+ * with, `{ input: "pointer" }` or a dragged-in item's input, so a policy that answers by input
26
+ * answers the preview as it will the drop. Preview segments get `data-invalid` when a policy
27
+ * rejects it and `data-warning` when one flags it.
27
28
  */
28
- readonly check?: (proposal: CalendarEventProposal<TEventId, TResourceId, TEvent>) => CalendarPolicyResult<TEvent, TEventId, TResourceId> | null;
29
+ readonly check?: (proposal: CalendarEventProposal<TEventId, TResourceId, TEvent>, detail: CalendarProposalDetail) => CalendarPolicyResult<TEvent, TEventId, TResourceId> | null;
29
30
  /**
30
31
  * Day columns of the time axis, matched to `[data-date]` elements without `data-all-day`: a
31
32
  * time grid's or a timeline's `columns`. A new array mid-gesture is picked up, as a view that
@@ -53,6 +54,14 @@ interface CalendarPointerOptions<TEvent, TEventId extends EventId, TResourceId e
53
54
  readonly scrollContainer?: {
54
55
  readonly current: Element | null;
55
56
  };
57
+ /**
58
+ * A ref to an element inside `scrollContainer` that scrolls sideways in its place while dragging
59
+ * near its left and right edges: in a view that scrolls each axis in an element of its own, so a
60
+ * swipe moves one axis at a time. Defaults to `scrollContainer`.
61
+ */
62
+ readonly sidewaysScrollContainer?: {
63
+ readonly current: Element | null;
64
+ };
56
65
  /** Wall-clock grid for time columns. Defaults to 15 minutes. */
57
66
  readonly snap?: WallTimeSnapOptions;
58
67
  }
@@ -82,8 +91,6 @@ interface CalendarPointerOptions<TEvent, TEventId extends EventId, TResourceId e
82
91
  * that detaches everything.
83
92
  */
84
93
  export declare function attachCalendarPointer<TEvent, TEventId extends EventId, TResourceId extends ResourceId>(region: HTMLElement, getOptions: () => CalendarPointerOptions<TEvent, TEventId, TResourceId>): () => void;
85
- //#endregion
86
- //#region src/drags.d.ts
87
94
  /** A point in viewport (client) coordinates. */
88
95
  interface CalendarPoint {
89
96
  readonly x: number;
@@ -166,8 +173,6 @@ type CalendarDragMonitor = (drag: CalendarEventDrag) => CalendarDragFollower | v
166
173
  * Returns a function that stops listening.
167
174
  */
168
175
  export declare function monitorCalendarDrags(monitor: CalendarDragMonitor): () => void;
169
- //#endregion
170
- //#region src/drop.d.ts
171
176
  /** What an item dragged in from outside the calendar becomes when it's dropped on a view. */
172
177
  interface CalendarDropSource<TEvent = unknown, TEventId extends EventId = EventId> {
173
178
  /**
@@ -238,8 +243,6 @@ interface CalendarDropSession<TEvent = unknown, TEventId extends EventId = Event
238
243
  * them or rested at one for a moment, so crossing an edge on the way in doesn't scroll it.
239
244
  */
240
245
  export declare function startCalendarDrop<TEvent = unknown, TEventId extends EventId = EventId, TResourceId extends ResourceId = ResourceId>(source: CalendarDropSource<TEvent, TEventId>, { input }?: CalendarDropOptions): CalendarDropSession<TEvent, TEventId, TResourceId>;
241
- //#endregion
242
- //#region src/event-id.d.ts
243
246
  /**
244
247
  * Attributes that identify an event element, for spreading onto it. `data-event-id` holds the ID
245
248
  * as text; numeric IDs add `data-event-id-type="number"`, so `1` and `"1"` stay distinct.
@@ -250,8 +253,6 @@ export declare function eventIdAttributes(id: EventId): {
250
253
  };
251
254
  /** The event ID an element carries through `eventIdAttributes`, or `null` without one. */
252
255
  export declare function eventIdOf(element: Element): EventId | null;
253
- //#endregion
254
- //#region src/regions.d.ts
255
256
  /** A calendar view's region, as a binding to a drag-and-drop library sees it. */
256
257
  interface CalendarRegion {
257
258
  /** Whether its gestures are off, as on a read-only root: then it takes no drops either. */
@@ -265,8 +266,6 @@ interface CalendarRegion {
265
266
  * function that stops listening.
266
267
  */
267
268
  export declare function observeCalendarRegions(observer: (regions: readonly CalendarRegion[]) => void): () => void;
268
- //#endregion
269
- //#region src/resource-id.d.ts
270
269
  /**
271
270
  * Attributes that place an element in a resource, for spreading onto a resource's column, row, or
272
271
  * cells. `data-resource-id` holds the ID as text, empty for the unassigned bucket (`null`); numeric
@@ -281,8 +280,6 @@ export declare function resourceIdAttributes(id: ResourceId | null): {
281
280
  * unassigned bucket, `undefined` outside any resource.
282
281
  */
283
282
  export declare function resourceIdOf(element: Element): ResourceId | null | undefined;
284
- //#endregion
285
- //#region src/use-calendar-pointer.d.ts
286
283
  /**
287
284
  * Pointer move, resize, and create for a view region; see `attachCalendarPointer` for the data
288
285
  * attributes the view renders. Returns a ref for the region element. Options are read when a
@@ -292,5 +289,4 @@ export declare function resourceIdOf(element: Element): ResourceId | null | unde
292
289
  * attaches the listeners again.
293
290
  */
294
291
  export declare function useCalendarPointer<TEvent, TEventId extends EventId, TResourceId extends ResourceId>(options: CalendarPointerOptions<TEvent, TEventId, TResourceId>): RefCallback<HTMLElement>;
295
- //#endregion
296
292
  export type { CalendarDragFollower, CalendarDragMonitor, CalendarDragPreview, CalendarDropOptions, CalendarDropSession, CalendarDropSource, CalendarEventDrag, CalendarPoint, CalendarPointerOptions, CalendarRect, CalendarRegion };
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import { belongsInTimeGridAllDayRow, createPlacementBetween, eventPlacement, formatPlacementRange, movePlacementToTarget, resizePlacementToTarget, showsInResource, splitEventsByDay, timeGridDateTimeAt, timedFragmentBox, timelineExtent } from "@moltenship/calendar-core";
3
3
  import { comparePlainDates, instantInterval, plainDateInterval } from "@moltenship/calendar-temporal";
4
4
  import { useCallback, useInsertionEffect, useRef } from "react";
5
- //#region src/auto-scroll.ts
5
+ // src/auto-scroll.ts
6
6
  const EDGE = 48;
7
7
  const MAXIMUM_STEP = 18;
8
8
  /** Pixels to scroll this frame along one axis: faster the deeper the pointer is in an edge band. */
@@ -72,18 +72,19 @@ var EdgeArming = class {
72
72
  }
73
73
  };
74
74
  /**
75
- * Scrolls `container` when a viewport point sits near its edges. Returns whether it moved, so the
76
- * caller re-reads geometry only after a scroll.
75
+ * Scrolls `container` when a viewport point sits near its edges, and `sideways` in its place at
76
+ * the left and right edges: a scroller nested in it that scrolls sideways. Returns whether either
77
+ * moved, so the caller re-reads geometry only after a scroll.
77
78
  */
78
- function autoScroll(container, x, y) {
79
+ function autoScroll(container, x, y, sideways = container) {
79
80
  const rect = bounds(container);
80
- const { scrollLeft, scrollTop } = container;
81
+ const { scrollTop } = container;
82
+ const { scrollLeft } = sideways;
81
83
  container.scrollTop += step(y, rect.top, rect.bottom);
82
- container.scrollLeft += step(x, rect.left, rect.right);
83
- return container.scrollTop !== scrollTop || container.scrollLeft !== scrollLeft;
84
+ sideways.scrollLeft += step(x, rect.left, rect.right);
85
+ return container.scrollTop !== scrollTop || sideways.scrollLeft !== scrollLeft;
84
86
  }
85
- //#endregion
86
- //#region src/drags.ts
87
+ // src/drags.ts
87
88
  const monitors = /* @__PURE__ */ new Set();
88
89
  /** Reports an application callback's error without breaking the gesture it heard about. */
89
90
  function reportCallbackError(error) {
@@ -136,8 +137,7 @@ function claimed(followers) {
136
137
  }
137
138
  });
138
139
  }
139
- //#endregion
140
- //#region src/event-id.ts
140
+ // src/event-id.ts
141
141
  /**
142
142
  * Attributes that identify an event element, for spreading onto it. `data-event-id` holds the ID
143
143
  * as text; numeric IDs add `data-event-id-type="number"`, so `1` and `"1"` stay distinct.
@@ -154,8 +154,7 @@ function eventIdOf(element) {
154
154
  if (id === null) return null;
155
155
  return element.getAttribute("data-event-id-type") === "number" ? Number(id) : id;
156
156
  }
157
- //#endregion
158
- //#region src/gestures.ts
157
+ // src/gestures.ts
159
158
  /** The snapped time under the pointer. The keyboard reaches the same targets through slots. */
160
159
  function interactionTarget(target, snap) {
161
160
  return target.kind === "day" ? target : {
@@ -229,8 +228,7 @@ function droppedPlacement(item, target, { snap, timeZone }) {
229
228
  start: at.at.toInstant()
230
229
  };
231
230
  }
232
- //#endregion
233
- //#region src/resource-id.ts
231
+ // src/resource-id.ts
234
232
  /**
235
233
  * Attributes that place an element in a resource, for spreading onto a resource's column, row, or
236
234
  * cells. `data-resource-id` holds the ID as text, empty for the unassigned bucket (`null`); numeric
@@ -254,8 +252,7 @@ function resourceIdOf(element) {
254
252
  if (id === "") return null;
255
253
  return holder.getAttribute("data-resource-id-type") === "number" ? Number(id) : id;
256
254
  }
257
- //#endregion
258
- //#region src/targets.ts
255
+ // src/targets.ts
259
256
  /** A view's time columns by ISO date, for matching `[data-date]` elements to them. */
260
257
  function columnsByDate(columns) {
261
258
  return new Map((columns ?? []).map((column) => [column.date.toString(), column]));
@@ -323,8 +320,7 @@ function targetAt(surface, x, y) {
323
320
  }
324
321
  return null;
325
322
  }
326
- //#endregion
327
- //#region src/ghost.ts
323
+ // src/ghost.ts
328
324
  function clips(overflow) {
329
325
  return overflow !== "" && overflow !== "visible";
330
326
  }
@@ -622,8 +618,7 @@ var GhostLayer = class {
622
618
  return segment;
623
619
  }
624
620
  };
625
- //#endregion
626
- //#region src/outcome.ts
621
+ // src/outcome.ts
627
622
  /**
628
623
  * Announces what became of a proposal from what `onPropose` returned: the transaction's result, or
629
624
  * from a handler that returns none, a commit of what was proposed. Resolves with the result, or
@@ -650,8 +645,7 @@ function settleProposal(returned, proposed, announce) {
650
645
  return result;
651
646
  });
652
647
  }
653
- //#endregion
654
- //#region src/regions.ts
648
+ // src/regions.ts
655
649
  const regions = /* @__PURE__ */ new Set();
656
650
  const observers = /* @__PURE__ */ new Set();
657
651
  function isEnabled(region) {
@@ -715,8 +709,7 @@ function regionAt(x, y) {
715
709
  } : null;
716
710
  return null;
717
711
  }
718
- //#endregion
719
- //#region src/attach-calendar-pointer.ts
712
+ // src/attach-calendar-pointer.ts
720
713
  const DEFAULT_SNAP$1 = {
721
714
  increment: 15,
722
715
  smallestUnit: "minute"
@@ -902,7 +895,7 @@ function attachCalendarPointer(region, getOptions) {
902
895
  current.placement = placement;
903
896
  if (changed) {
904
897
  const proposed = proposal(current);
905
- current.check = proposed === null ? null : getOptions().check?.(proposed) ?? null;
898
+ current.check = proposed === null ? null : getOptions().check?.(proposed, pointerInput) ?? null;
906
899
  getOptions().onPreview?.({
907
900
  eventId: current.gesture.kind === "create" ? null : current.gesture.event.id,
908
901
  proposed: placement
@@ -944,7 +937,7 @@ function attachCalendarPointer(region, getOptions) {
944
937
  const current = session;
945
938
  if (current === null) return;
946
939
  trackEdges(current);
947
- if (!(current.claimed || !current.edges.armed) && autoScroll(current.scrollContainer, current.point.x, current.point.y) && preview(current, true)) announce(current, { phase: "step" });
940
+ if (!(current.claimed || !current.edges.armed) && autoScroll(current.scrollContainer, current.point.x, current.point.y, current.sideways) && preview(current, true)) announce(current, { phase: "step" });
948
941
  current.frame = requestAnimationFrame(scrollFrame);
949
942
  }
950
943
  function activate(current) {
@@ -1113,6 +1106,7 @@ function attachCalendarPointer(region, getOptions) {
1113
1106
  const target = targetAt(surface, event.clientX, event.clientY);
1114
1107
  const gesture = target === null ? null : gestureFor(event.target, target, options.events);
1115
1108
  if (gesture === null) return;
1109
+ const scrollContainer = options.scrollContainer?.current ?? scrollableAncestor(event.target);
1116
1110
  const current = {
1117
1111
  active: false,
1118
1112
  announcer: options.announcer,
@@ -1137,8 +1131,9 @@ function attachCalendarPointer(region, getOptions) {
1137
1131
  },
1138
1132
  pointerId: event.pointerId,
1139
1133
  pointerType: event.pointerType,
1140
- scrollContainer: options.scrollContainer?.current ?? scrollableAncestor(event.target),
1134
+ scrollContainer,
1141
1135
  shown: null,
1136
+ sideways: options.sidewaysScrollContainer?.current ?? scrollContainer,
1142
1137
  surface,
1143
1138
  surfaceColumns: options.columns,
1144
1139
  touchTarget: event.pointerType === "touch" && event.target !== region ? event.target : null,
@@ -1181,8 +1176,7 @@ function attachCalendarPointer(region, getOptions) {
1181
1176
  unregister();
1182
1177
  };
1183
1178
  }
1184
- //#endregion
1185
- //#region src/drop.ts
1179
+ // src/drop.ts
1186
1180
  const DEFAULT_DURATION = { hours: 1 };
1187
1181
  const DEFAULT_SNAP = {
1188
1182
  increment: 15,
@@ -1191,6 +1185,7 @@ const DEFAULT_SNAP = {
1191
1185
  function regionOver(region, hit, eventId) {
1192
1186
  const options = region.getOptions();
1193
1187
  const event = eventId === void 0 ? void 0 : options.events.get(eventId);
1188
+ const scrollContainer = options.scrollContainer?.current ?? scrollableAncestor(hit);
1194
1189
  return {
1195
1190
  edges: new EdgeArming(false),
1196
1191
  ghost: new GhostLayer(region.element, options.ghostClassName),
@@ -1203,7 +1198,8 @@ function regionOver(region, hit, eventId) {
1203
1198
  timeZone: options.timeZone
1204
1199
  },
1205
1200
  region,
1206
- scrollContainer: options.scrollContainer?.current ?? scrollableAncestor(hit),
1201
+ scrollContainer,
1202
+ sideways: options.sidewaysScrollContainer?.current ?? scrollContainer,
1207
1203
  surface: {
1208
1204
  clippers: /* @__PURE__ */ new Map(),
1209
1205
  columns: columnsByDate(options.columns),
@@ -1328,7 +1324,7 @@ function startCalendarDrop(source, { input = "pointer" } = {}) {
1328
1324
  } else {
1329
1325
  if (changed) {
1330
1326
  const proposed = proposal(current);
1331
- check = proposed === null ? null : options.check?.(proposed) ?? null;
1327
+ check = proposed === null ? null : options.check?.(proposed, detail) ?? null;
1332
1328
  options.onPreview?.({
1333
1329
  eventId: source.eventId ?? null,
1334
1330
  proposed: next
@@ -1356,7 +1352,7 @@ function startCalendarDrop(source, { input = "pointer" } = {}) {
1356
1352
  if (ended) return;
1357
1353
  if (over !== null && !takesDrops(over.region)) update();
1358
1354
  if (arm() && over !== null && point !== null) {
1359
- if (autoScroll(over.scrollContainer, point.x, point.y)) update(true);
1355
+ if (autoScroll(over.scrollContainer, point.x, point.y, over.sideways)) update(true);
1360
1356
  }
1361
1357
  frame = requestAnimationFrame(scrollFrame);
1362
1358
  }
@@ -1405,8 +1401,7 @@ function startCalendarDrop(source, { input = "pointer" } = {}) {
1405
1401
  }
1406
1402
  };
1407
1403
  }
1408
- //#endregion
1409
- //#region src/use-calendar-pointer.ts
1404
+ // src/use-calendar-pointer.ts
1410
1405
  /**
1411
1406
  * Pointer move, resize, and create for a view region; see `attachCalendarPointer` for the data
1412
1407
  * attributes the view renders. Returns a ref for the region element. Options are read when a
@@ -1423,5 +1418,4 @@ function useCalendarPointer(options) {
1423
1418
  const disabled = options.disabled === true;
1424
1419
  return useCallback((element) => element === null ? void 0 : attachCalendarPointer(element, () => latest.current), [disabled]);
1425
1420
  }
1426
- //#endregion
1427
1421
  export { attachCalendarPointer, eventIdAttributes, eventIdOf, monitorCalendarDrags, observeCalendarRegions, resourceIdAttributes, resourceIdOf, startCalendarDrop, useCalendarPointer };
package/package.json CHANGED
@@ -1,7 +1,18 @@
1
1
  {
2
2
  "name": "@moltenship/calendar-dnd",
3
- "version": "1.0.0-rc.1",
3
+ "version": "2.0.0-beta.1",
4
4
  "description": "Pointer drag, resize, and create interactions for Moltenship Time views.",
5
+ "keywords": [
6
+ "calendar",
7
+ "drag-and-drop",
8
+ "event-calendar",
9
+ "pointer-events",
10
+ "react",
11
+ "resize",
12
+ "scheduler",
13
+ "temporal",
14
+ "typescript"
15
+ ],
5
16
  "homepage": "https://time.molten.sh/docs/interactions",
6
17
  "bugs": {
7
18
  "url": "https://github.com/Moltenship/time/issues"
@@ -28,25 +39,24 @@
28
39
  "access": "public"
29
40
  },
30
41
  "dependencies": {
31
- "@moltenship/calendar-core": "1.0.0-rc.1",
32
- "@moltenship/calendar-temporal": "1.0.0-rc.1"
42
+ "@moltenship/calendar-core": "2.0.0-beta.1",
43
+ "@moltenship/calendar-temporal": "2.0.0-beta.1"
33
44
  },
34
45
  "devDependencies": {
35
46
  "@types/react": "19.3.0",
36
47
  "@types/react-dom": "19.3.0",
37
- "jsdom": "30.1.2",
38
- "react": "19.3.0",
39
- "react-dom": "19.3.0",
48
+ "jsdom": "30.1.3",
49
+ "react": "19.3.1",
50
+ "react-dom": "19.3.1",
40
51
  "typescript": "^7.0.2",
41
- "vite": "npm:@voidzero-dev/vite-plus-core@1.1.0",
42
- "vite-plus": "1.1.0"
52
+ "vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
53
+ "vite-plus": "1.4.0"
43
54
  },
44
55
  "peerDependencies": {
45
56
  "react": "^19.0.0"
46
57
  },
47
58
  "scripts": {
48
59
  "build": "vp pack",
49
- "check": "vp check",
50
60
  "dev": "vp pack --watch",
51
61
  "test": "vp test --passWithNoTests"
52
62
  }