@moltenship/calendar-dnd 1.0.0-rc.2 → 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 +5 -17
- package/dist/index.mjs +14 -26
- package/package.json +19 -9
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`.
|
|
26
|
-
*
|
|
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
|
|
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
|
|
@@ -90,8 +91,6 @@ interface CalendarPointerOptions<TEvent, TEventId extends EventId, TResourceId e
|
|
|
90
91
|
* that detaches everything.
|
|
91
92
|
*/
|
|
92
93
|
export declare function attachCalendarPointer<TEvent, TEventId extends EventId, TResourceId extends ResourceId>(region: HTMLElement, getOptions: () => CalendarPointerOptions<TEvent, TEventId, TResourceId>): () => void;
|
|
93
|
-
//#endregion
|
|
94
|
-
//#region src/drags.d.ts
|
|
95
94
|
/** A point in viewport (client) coordinates. */
|
|
96
95
|
interface CalendarPoint {
|
|
97
96
|
readonly x: number;
|
|
@@ -174,8 +173,6 @@ type CalendarDragMonitor = (drag: CalendarEventDrag) => CalendarDragFollower | v
|
|
|
174
173
|
* Returns a function that stops listening.
|
|
175
174
|
*/
|
|
176
175
|
export declare function monitorCalendarDrags(monitor: CalendarDragMonitor): () => void;
|
|
177
|
-
//#endregion
|
|
178
|
-
//#region src/drop.d.ts
|
|
179
176
|
/** What an item dragged in from outside the calendar becomes when it's dropped on a view. */
|
|
180
177
|
interface CalendarDropSource<TEvent = unknown, TEventId extends EventId = EventId> {
|
|
181
178
|
/**
|
|
@@ -246,8 +243,6 @@ interface CalendarDropSession<TEvent = unknown, TEventId extends EventId = Event
|
|
|
246
243
|
* them or rested at one for a moment, so crossing an edge on the way in doesn't scroll it.
|
|
247
244
|
*/
|
|
248
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>;
|
|
249
|
-
//#endregion
|
|
250
|
-
//#region src/event-id.d.ts
|
|
251
246
|
/**
|
|
252
247
|
* Attributes that identify an event element, for spreading onto it. `data-event-id` holds the ID
|
|
253
248
|
* as text; numeric IDs add `data-event-id-type="number"`, so `1` and `"1"` stay distinct.
|
|
@@ -258,8 +253,6 @@ export declare function eventIdAttributes(id: EventId): {
|
|
|
258
253
|
};
|
|
259
254
|
/** The event ID an element carries through `eventIdAttributes`, or `null` without one. */
|
|
260
255
|
export declare function eventIdOf(element: Element): EventId | null;
|
|
261
|
-
//#endregion
|
|
262
|
-
//#region src/regions.d.ts
|
|
263
256
|
/** A calendar view's region, as a binding to a drag-and-drop library sees it. */
|
|
264
257
|
interface CalendarRegion {
|
|
265
258
|
/** Whether its gestures are off, as on a read-only root: then it takes no drops either. */
|
|
@@ -273,8 +266,6 @@ interface CalendarRegion {
|
|
|
273
266
|
* function that stops listening.
|
|
274
267
|
*/
|
|
275
268
|
export declare function observeCalendarRegions(observer: (regions: readonly CalendarRegion[]) => void): () => void;
|
|
276
|
-
//#endregion
|
|
277
|
-
//#region src/resource-id.d.ts
|
|
278
269
|
/**
|
|
279
270
|
* Attributes that place an element in a resource, for spreading onto a resource's column, row, or
|
|
280
271
|
* cells. `data-resource-id` holds the ID as text, empty for the unassigned bucket (`null`); numeric
|
|
@@ -289,8 +280,6 @@ export declare function resourceIdAttributes(id: ResourceId | null): {
|
|
|
289
280
|
* unassigned bucket, `undefined` outside any resource.
|
|
290
281
|
*/
|
|
291
282
|
export declare function resourceIdOf(element: Element): ResourceId | null | undefined;
|
|
292
|
-
//#endregion
|
|
293
|
-
//#region src/use-calendar-pointer.d.ts
|
|
294
283
|
/**
|
|
295
284
|
* Pointer move, resize, and create for a view region; see `attachCalendarPointer` for the data
|
|
296
285
|
* attributes the view renders. Returns a ref for the region element. Options are read when a
|
|
@@ -300,5 +289,4 @@ export declare function resourceIdOf(element: Element): ResourceId | null | unde
|
|
|
300
289
|
* attaches the listeners again.
|
|
301
290
|
*/
|
|
302
291
|
export declare function useCalendarPointer<TEvent, TEventId extends EventId, TResourceId extends ResourceId>(options: CalendarPointerOptions<TEvent, TEventId, TResourceId>): RefCallback<HTMLElement>;
|
|
303
|
-
//#endregion
|
|
304
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
|
-
|
|
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. */
|
|
@@ -84,8 +84,7 @@ function autoScroll(container, x, y, sideways = container) {
|
|
|
84
84
|
sideways.scrollLeft += step(x, rect.left, rect.right);
|
|
85
85
|
return container.scrollTop !== scrollTop || sideways.scrollLeft !== scrollLeft;
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
//#region src/drags.ts
|
|
87
|
+
// src/drags.ts
|
|
89
88
|
const monitors = /* @__PURE__ */ new Set();
|
|
90
89
|
/** Reports an application callback's error without breaking the gesture it heard about. */
|
|
91
90
|
function reportCallbackError(error) {
|
|
@@ -138,8 +137,7 @@ function claimed(followers) {
|
|
|
138
137
|
}
|
|
139
138
|
});
|
|
140
139
|
}
|
|
141
|
-
|
|
142
|
-
//#region src/event-id.ts
|
|
140
|
+
// src/event-id.ts
|
|
143
141
|
/**
|
|
144
142
|
* Attributes that identify an event element, for spreading onto it. `data-event-id` holds the ID
|
|
145
143
|
* as text; numeric IDs add `data-event-id-type="number"`, so `1` and `"1"` stay distinct.
|
|
@@ -156,8 +154,7 @@ function eventIdOf(element) {
|
|
|
156
154
|
if (id === null) return null;
|
|
157
155
|
return element.getAttribute("data-event-id-type") === "number" ? Number(id) : id;
|
|
158
156
|
}
|
|
159
|
-
|
|
160
|
-
//#region src/gestures.ts
|
|
157
|
+
// src/gestures.ts
|
|
161
158
|
/** The snapped time under the pointer. The keyboard reaches the same targets through slots. */
|
|
162
159
|
function interactionTarget(target, snap) {
|
|
163
160
|
return target.kind === "day" ? target : {
|
|
@@ -231,8 +228,7 @@ function droppedPlacement(item, target, { snap, timeZone }) {
|
|
|
231
228
|
start: at.at.toInstant()
|
|
232
229
|
};
|
|
233
230
|
}
|
|
234
|
-
|
|
235
|
-
//#region src/resource-id.ts
|
|
231
|
+
// src/resource-id.ts
|
|
236
232
|
/**
|
|
237
233
|
* Attributes that place an element in a resource, for spreading onto a resource's column, row, or
|
|
238
234
|
* cells. `data-resource-id` holds the ID as text, empty for the unassigned bucket (`null`); numeric
|
|
@@ -256,8 +252,7 @@ function resourceIdOf(element) {
|
|
|
256
252
|
if (id === "") return null;
|
|
257
253
|
return holder.getAttribute("data-resource-id-type") === "number" ? Number(id) : id;
|
|
258
254
|
}
|
|
259
|
-
|
|
260
|
-
//#region src/targets.ts
|
|
255
|
+
// src/targets.ts
|
|
261
256
|
/** A view's time columns by ISO date, for matching `[data-date]` elements to them. */
|
|
262
257
|
function columnsByDate(columns) {
|
|
263
258
|
return new Map((columns ?? []).map((column) => [column.date.toString(), column]));
|
|
@@ -325,8 +320,7 @@ function targetAt(surface, x, y) {
|
|
|
325
320
|
}
|
|
326
321
|
return null;
|
|
327
322
|
}
|
|
328
|
-
|
|
329
|
-
//#region src/ghost.ts
|
|
323
|
+
// src/ghost.ts
|
|
330
324
|
function clips(overflow) {
|
|
331
325
|
return overflow !== "" && overflow !== "visible";
|
|
332
326
|
}
|
|
@@ -624,8 +618,7 @@ var GhostLayer = class {
|
|
|
624
618
|
return segment;
|
|
625
619
|
}
|
|
626
620
|
};
|
|
627
|
-
|
|
628
|
-
//#region src/outcome.ts
|
|
621
|
+
// src/outcome.ts
|
|
629
622
|
/**
|
|
630
623
|
* Announces what became of a proposal from what `onPropose` returned: the transaction's result, or
|
|
631
624
|
* from a handler that returns none, a commit of what was proposed. Resolves with the result, or
|
|
@@ -652,8 +645,7 @@ function settleProposal(returned, proposed, announce) {
|
|
|
652
645
|
return result;
|
|
653
646
|
});
|
|
654
647
|
}
|
|
655
|
-
|
|
656
|
-
//#region src/regions.ts
|
|
648
|
+
// src/regions.ts
|
|
657
649
|
const regions = /* @__PURE__ */ new Set();
|
|
658
650
|
const observers = /* @__PURE__ */ new Set();
|
|
659
651
|
function isEnabled(region) {
|
|
@@ -717,8 +709,7 @@ function regionAt(x, y) {
|
|
|
717
709
|
} : null;
|
|
718
710
|
return null;
|
|
719
711
|
}
|
|
720
|
-
|
|
721
|
-
//#region src/attach-calendar-pointer.ts
|
|
712
|
+
// src/attach-calendar-pointer.ts
|
|
722
713
|
const DEFAULT_SNAP$1 = {
|
|
723
714
|
increment: 15,
|
|
724
715
|
smallestUnit: "minute"
|
|
@@ -904,7 +895,7 @@ function attachCalendarPointer(region, getOptions) {
|
|
|
904
895
|
current.placement = placement;
|
|
905
896
|
if (changed) {
|
|
906
897
|
const proposed = proposal(current);
|
|
907
|
-
current.check = proposed === null ? null : getOptions().check?.(proposed) ?? null;
|
|
898
|
+
current.check = proposed === null ? null : getOptions().check?.(proposed, pointerInput) ?? null;
|
|
908
899
|
getOptions().onPreview?.({
|
|
909
900
|
eventId: current.gesture.kind === "create" ? null : current.gesture.event.id,
|
|
910
901
|
proposed: placement
|
|
@@ -1185,8 +1176,7 @@ function attachCalendarPointer(region, getOptions) {
|
|
|
1185
1176
|
unregister();
|
|
1186
1177
|
};
|
|
1187
1178
|
}
|
|
1188
|
-
|
|
1189
|
-
//#region src/drop.ts
|
|
1179
|
+
// src/drop.ts
|
|
1190
1180
|
const DEFAULT_DURATION = { hours: 1 };
|
|
1191
1181
|
const DEFAULT_SNAP = {
|
|
1192
1182
|
increment: 15,
|
|
@@ -1334,7 +1324,7 @@ function startCalendarDrop(source, { input = "pointer" } = {}) {
|
|
|
1334
1324
|
} else {
|
|
1335
1325
|
if (changed) {
|
|
1336
1326
|
const proposed = proposal(current);
|
|
1337
|
-
check = proposed === null ? null : options.check?.(proposed) ?? null;
|
|
1327
|
+
check = proposed === null ? null : options.check?.(proposed, detail) ?? null;
|
|
1338
1328
|
options.onPreview?.({
|
|
1339
1329
|
eventId: source.eventId ?? null,
|
|
1340
1330
|
proposed: next
|
|
@@ -1411,8 +1401,7 @@ function startCalendarDrop(source, { input = "pointer" } = {}) {
|
|
|
1411
1401
|
}
|
|
1412
1402
|
};
|
|
1413
1403
|
}
|
|
1414
|
-
|
|
1415
|
-
//#region src/use-calendar-pointer.ts
|
|
1404
|
+
// src/use-calendar-pointer.ts
|
|
1416
1405
|
/**
|
|
1417
1406
|
* Pointer move, resize, and create for a view region; see `attachCalendarPointer` for the data
|
|
1418
1407
|
* attributes the view renders. Returns a ref for the region element. Options are read when a
|
|
@@ -1429,5 +1418,4 @@ function useCalendarPointer(options) {
|
|
|
1429
1418
|
const disabled = options.disabled === true;
|
|
1430
1419
|
return useCallback((element) => element === null ? void 0 : attachCalendarPointer(element, () => latest.current), [disabled]);
|
|
1431
1420
|
}
|
|
1432
|
-
//#endregion
|
|
1433
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": "
|
|
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": "
|
|
32
|
-
"@moltenship/calendar-temporal": "
|
|
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.
|
|
38
|
-
"react": "19.3.
|
|
39
|
-
"react-dom": "19.3.
|
|
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.
|
|
42
|
-
"vite-plus": "1.
|
|
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
|
}
|