@event-calendar/core 5.0.5 → 5.1.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 +15 -4
- package/dist/index.css +2 -2
- package/dist/index.js +2201 -2128
- package/package.json +2 -2
- package/src/Buttons.svelte +36 -37
- package/src/Calendar.svelte +34 -37
- package/src/Toolbar.svelte +4 -4
- package/src/lib/components/BaseDay.svelte +13 -10
- package/src/lib/components/BaseEvent.svelte +17 -17
- package/src/lib/components/ColHead.svelte +6 -6
- package/src/lib/components/DayHeader.svelte +3 -3
- package/src/lib/components/InteractableEvent.svelte +7 -8
- package/src/lib/derived.js +80 -0
- package/src/lib/index.js +1 -2
- package/src/lib/slots.js +16 -16
- package/src/lib/utils.js +4 -9
- package/src/lib/view.js +0 -8
- package/src/plugins/day-grid/Day.svelte +25 -23
- package/src/plugins/day-grid/Event.svelte +15 -13
- package/src/plugins/day-grid/Popup.svelte +12 -12
- package/src/plugins/day-grid/View.svelte +24 -36
- package/src/plugins/day-grid/derived.js +102 -0
- package/src/plugins/day-grid/index.js +47 -36
- package/src/plugins/day-grid/state.svelte.js +19 -0
- package/src/plugins/interaction/Action.svelte +108 -76
- package/src/plugins/interaction/Auxiliary.svelte +9 -38
- package/src/plugins/interaction/Pointer.svelte +12 -17
- package/src/plugins/interaction/Resizer.svelte +9 -7
- package/src/plugins/interaction/effects.js +37 -0
- package/src/plugins/interaction/index.js +44 -38
- package/src/plugins/interaction/lib/utils.js +1 -1
- package/src/plugins/interaction/state.svelte.js +12 -0
- package/src/plugins/list/Day.svelte +8 -7
- package/src/plugins/list/Event.svelte +3 -3
- package/src/plugins/list/View.svelte +18 -13
- package/src/plugins/list/index.js +51 -43
- package/src/plugins/list/state.svelte.js +8 -0
- package/src/plugins/resource-time-grid/Label.svelte +8 -8
- package/src/plugins/resource-time-grid/View.svelte +38 -17
- package/src/plugins/resource-time-grid/derived.js +67 -0
- package/src/plugins/resource-time-grid/index.js +34 -28
- package/src/plugins/resource-time-grid/state.svelte.js +21 -0
- package/src/plugins/resource-timeline/Day.svelte +9 -4
- package/src/plugins/resource-timeline/Event.svelte +7 -6
- package/src/plugins/resource-timeline/Expander.svelte +7 -6
- package/src/plugins/resource-timeline/NowIndicator.svelte +10 -11
- package/src/plugins/resource-timeline/View.svelte +45 -63
- package/src/plugins/resource-timeline/derived.js +167 -0
- package/src/plugins/resource-timeline/index.js +17 -21
- package/src/plugins/resource-timeline/lib.js +4 -65
- package/src/plugins/resource-timeline/state.svelte.js +18 -0
- package/src/plugins/time-grid/Day.svelte +7 -2
- package/src/plugins/time-grid/Event.svelte +6 -6
- package/src/plugins/time-grid/NowIndicator.svelte +10 -9
- package/src/plugins/time-grid/View.svelte +46 -59
- package/src/plugins/time-grid/derived.js +162 -0
- package/src/plugins/time-grid/index.js +31 -25
- package/src/plugins/time-grid/lib.js +18 -74
- package/src/plugins/time-grid/options.js +21 -16
- package/src/plugins/time-grid/state.svelte.js +44 -0
- package/src/storage/derived.js +144 -0
- package/src/storage/effects.js +156 -0
- package/src/storage/options.svelte.js +275 -0
- package/src/storage/state.svelte.js +69 -0
- package/src/styles/events.css +1 -1
- package/src/Auxiliary.svelte +0 -47
- package/src/lib/debounce.js +0 -20
- package/src/lib/stores.js +0 -63
- package/src/plugins/day-grid/lib.js +0 -61
- package/src/plugins/day-grid/stores.js +0 -5
- package/src/plugins/resource-time-grid/lib.js +0 -31
- package/src/plugins/resource-time-grid/stores.js +0 -34
- package/src/plugins/resource-timeline/Header.svelte +0 -44
- package/src/plugins/resource-timeline/Label.svelte +0 -38
- package/src/plugins/resource-timeline/stores.js +0 -48
- package/src/plugins/time-grid/stores.js +0 -49
- package/src/storage/options.js +0 -136
- package/src/storage/state.js +0 -168
- package/src/storage/stores.js +0 -234
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {SvelteMap} from 'svelte/reactivity';
|
|
2
|
+
import {intl} from '#lib';
|
|
3
|
+
import {colsCount, eventChunks, grid, iEventChunks} from './derived.js';
|
|
4
|
+
|
|
5
|
+
export default class ViewState {
|
|
6
|
+
constructor(mainState) {
|
|
7
|
+
this.colsCount = $derived.by(colsCount(mainState));
|
|
8
|
+
this.grid = $derived.by(grid(mainState, this));
|
|
9
|
+
this.gridEl = $state();
|
|
10
|
+
let {chunks, bgChunks} = $derived.by(eventChunks(mainState, this));
|
|
11
|
+
this.chunks = $derived(chunks);
|
|
12
|
+
this.bgChunks = $derived(bgChunks);
|
|
13
|
+
this.iChunks = $derived.by(iEventChunks(mainState, this));
|
|
14
|
+
this.hiddenChunks = new SvelteMap();
|
|
15
|
+
this.intlDayCell = $derived.by(intl(mainState, 'dayCellFormat'));
|
|
16
|
+
this.intlDayPopover = $derived.by(intl(mainState, 'dayPopoverFormat'));
|
|
17
|
+
this.popupDay = $state(null);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
import {getContext, onMount} from 'svelte';
|
|
3
3
|
import {
|
|
4
4
|
addDay, addDuration, ancestor, assign, cloneDate, cloneEvent, copyTime, createDuration, getElementWithPayload,
|
|
5
|
-
getPayload, isFunction, isRtl, listen,
|
|
6
|
-
|
|
5
|
+
getPayload, isFunction, isRtl, listen, max, min, noop, rect, runAll, subtractDay, subtractDuration,
|
|
6
|
+
toEventWithLocalDates, toISOString, toLocalDate, toViewWithLocalDates
|
|
7
7
|
} from '#lib';
|
|
8
8
|
import {animate, limit, eventDraggable} from './lib';
|
|
9
9
|
|
|
10
|
-
let
|
|
10
|
+
let mainState = getContext('state');
|
|
11
|
+
let {events, iEvents, features, view, mainEl, options: {dateClick, dragConstraint, dragScroll, editable,
|
|
11
12
|
eventStartEditable, eventDragMinDistance, eventDragStart, eventDragStop, eventDrop,
|
|
12
13
|
eventLongPressDelay, eventResizeStart, eventResizeStop, eventResize, longPressDelay, resizeConstraint,
|
|
13
14
|
selectable, select: selectFn, selectBackgroundColor, selectConstraint, selectLongPressDelay, selectMinDistance,
|
|
14
|
-
|
|
15
|
+
unselect: unselectFn, unselectAuto, unselectCancel, validRange}
|
|
16
|
+
} = $derived(mainState);
|
|
15
17
|
|
|
16
18
|
const ACTION_DRAG = 1;
|
|
17
19
|
const ACTION_RESIZE_END = 2;
|
|
@@ -22,6 +24,7 @@
|
|
|
22
24
|
let action;
|
|
23
25
|
let interacting;
|
|
24
26
|
let event;
|
|
27
|
+
let iEvent;
|
|
25
28
|
let display;
|
|
26
29
|
let date, newDate;
|
|
27
30
|
let resource, newResource;
|
|
@@ -38,20 +41,21 @@
|
|
|
38
41
|
let timer; // timer for long press delays
|
|
39
42
|
let viewport;
|
|
40
43
|
let margin;
|
|
44
|
+
let snapDuration; // step for timeGrid views
|
|
41
45
|
let extraDuration; // extra duration for zero duration events
|
|
42
46
|
|
|
43
47
|
export function draggable(event) {
|
|
44
|
-
return eventDraggable(event,
|
|
48
|
+
return eventDraggable(event, eventStartEditable, editable);
|
|
45
49
|
}
|
|
46
50
|
|
|
47
|
-
export function drag(eventToDrag, jsEvent, forceDate, forceMargin) {
|
|
51
|
+
export function drag(eventToDrag, jsEvent, forceDate, forceMargin, snap) {
|
|
48
52
|
if (!action) {
|
|
49
53
|
action = validJsEvent(jsEvent) ? ACTION_DRAG : ACTION_NO_ACTION;
|
|
50
54
|
|
|
51
55
|
if (complexAction()) {
|
|
52
56
|
event = eventToDrag;
|
|
53
57
|
|
|
54
|
-
common(jsEvent);
|
|
58
|
+
common(jsEvent, snap);
|
|
55
59
|
|
|
56
60
|
if (forceDate) {
|
|
57
61
|
// Force date in popup
|
|
@@ -69,7 +73,7 @@
|
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
75
|
|
|
72
|
-
export function resize(eventToResize, jsEvent, start, axis, forceDate, forceMargin, zeroDuration) {
|
|
76
|
+
export function resize(eventToResize, jsEvent, start, axis, forceDate, forceMargin, zeroDuration, snap) {
|
|
73
77
|
if (!action) {
|
|
74
78
|
action = validJsEvent(jsEvent) ? (
|
|
75
79
|
start ? ACTION_RESIZE_START : ACTION_RESIZE_END
|
|
@@ -78,7 +82,7 @@
|
|
|
78
82
|
if (complexAction()) {
|
|
79
83
|
event = eventToResize;
|
|
80
84
|
|
|
81
|
-
common(jsEvent);
|
|
85
|
+
common(jsEvent, snap);
|
|
82
86
|
|
|
83
87
|
if (forceDate) {
|
|
84
88
|
// Force date in popup
|
|
@@ -100,7 +104,7 @@
|
|
|
100
104
|
subtractDay(minResize);
|
|
101
105
|
}
|
|
102
106
|
} else {
|
|
103
|
-
subtractDuration(minResize,
|
|
107
|
+
subtractDuration(minResize, snapDuration);
|
|
104
108
|
if (minResize < event.start) {
|
|
105
109
|
minResize = event.start;
|
|
106
110
|
}
|
|
@@ -116,7 +120,7 @@
|
|
|
116
120
|
addDay(minResize);
|
|
117
121
|
}
|
|
118
122
|
} else {
|
|
119
|
-
addDuration(minResize,
|
|
123
|
+
addDuration(minResize, snapDuration);
|
|
120
124
|
if (minResize > event.end) {
|
|
121
125
|
minResize = event.end;
|
|
122
126
|
}
|
|
@@ -124,13 +128,13 @@
|
|
|
124
128
|
// and resizer coordinates in browser
|
|
125
129
|
date = event.end;
|
|
126
130
|
if (!zeroDuration) {
|
|
127
|
-
date = subtractDuration(cloneDate(date),
|
|
131
|
+
date = subtractDuration(cloneDate(date), snapDuration);
|
|
128
132
|
}
|
|
129
133
|
}
|
|
130
134
|
|
|
131
135
|
// Handle zero duration events
|
|
132
136
|
if (zeroDuration && !allDay) {
|
|
133
|
-
extraDuration =
|
|
137
|
+
extraDuration = snapDuration;
|
|
134
138
|
}
|
|
135
139
|
}
|
|
136
140
|
|
|
@@ -139,18 +143,18 @@
|
|
|
139
143
|
}
|
|
140
144
|
}
|
|
141
145
|
|
|
142
|
-
export function select(jsEvent) {
|
|
146
|
+
export function select(jsEvent, snap) {
|
|
143
147
|
if (!action) {
|
|
144
148
|
action = validJsEvent(jsEvent) ? (
|
|
145
|
-
|
|
149
|
+
selectable && !features.includes('list') ? ACTION_SELECT : ACTION_CLICK
|
|
146
150
|
) : ACTION_NO_ACTION;
|
|
147
151
|
|
|
148
152
|
if (complexAction()) {
|
|
149
|
-
common(jsEvent);
|
|
153
|
+
common(jsEvent, snap);
|
|
150
154
|
|
|
151
155
|
iClass = 'selecting';
|
|
152
156
|
|
|
153
|
-
selectStep = allDay ? createDuration({day: 1}) :
|
|
157
|
+
selectStep = allDay ? createDuration({day: 1}) : snapDuration;
|
|
154
158
|
|
|
155
159
|
// Create dummy source event
|
|
156
160
|
event = {
|
|
@@ -171,16 +175,18 @@
|
|
|
171
175
|
}
|
|
172
176
|
}
|
|
173
177
|
|
|
174
|
-
function common(jsEvent) {
|
|
178
|
+
function common(jsEvent, snap) {
|
|
175
179
|
window.getSelection().removeAllRanges();
|
|
176
180
|
|
|
177
181
|
fromX = toX = jsEvent.clientX;
|
|
178
182
|
fromY = toY = jsEvent.clientY;
|
|
179
183
|
|
|
184
|
+
snapDuration = snap?.duration;
|
|
185
|
+
|
|
180
186
|
let dayEl = getElementWithPayload(toX, toY);
|
|
181
187
|
({allDay, date, resource} = getPayload(dayEl)(toX, toY));
|
|
182
188
|
|
|
183
|
-
allDaySlot =
|
|
189
|
+
allDaySlot = mainEl !== ancestor(dayEl, 3);
|
|
184
190
|
gridEl = ancestor(dayEl, 1);
|
|
185
191
|
calcViewport();
|
|
186
192
|
|
|
@@ -191,24 +197,24 @@
|
|
|
191
197
|
interacting = true;
|
|
192
198
|
move(jsEvent);
|
|
193
199
|
}
|
|
194
|
-
}, (selecting() ?
|
|
200
|
+
}, (selecting() ? selectLongPressDelay : eventLongPressDelay) ?? longPressDelay);
|
|
195
201
|
}
|
|
196
202
|
}
|
|
197
203
|
|
|
198
204
|
function move(jsEvent) {
|
|
199
205
|
if (
|
|
200
206
|
interacting ||
|
|
201
|
-
jsEvent && jsEvent.pointerType === 'mouse' && distance() >= (selecting() ?
|
|
207
|
+
jsEvent && jsEvent.pointerType === 'mouse' && distance() >= (selecting() ? selectMinDistance : eventDragMinDistance)
|
|
202
208
|
) {
|
|
203
209
|
interacting = true;
|
|
204
210
|
unselect(jsEvent);
|
|
205
|
-
|
|
211
|
+
mainState.iClass = iClass;
|
|
206
212
|
|
|
207
|
-
if (
|
|
213
|
+
if (!iEvent) {
|
|
208
214
|
if (selecting()) {
|
|
209
215
|
createIEventSelect();
|
|
210
216
|
} else {
|
|
211
|
-
createIEvent(jsEvent, resizing() ?
|
|
217
|
+
createIEvent(jsEvent, resizing() ? eventResizeStart : eventDragStart);
|
|
212
218
|
}
|
|
213
219
|
}
|
|
214
220
|
|
|
@@ -218,8 +224,8 @@
|
|
|
218
224
|
({allDay: newAllDay, date: newDate, resource: newResource} = payload);
|
|
219
225
|
|
|
220
226
|
if (newAllDay === allDay) {
|
|
221
|
-
let candidate = copyIEventData({},
|
|
222
|
-
let constraintFn =
|
|
227
|
+
let candidate = copyIEventData({}, iEvent);
|
|
228
|
+
let constraintFn = resizeConstraint;
|
|
223
229
|
delta = createDuration((newDate - date) / 1000);
|
|
224
230
|
if (resizingStart()) {
|
|
225
231
|
// Resizing start
|
|
@@ -247,7 +253,7 @@
|
|
|
247
253
|
} else {
|
|
248
254
|
candidate.start = event.start;
|
|
249
255
|
}
|
|
250
|
-
constraintFn =
|
|
256
|
+
constraintFn = selectConstraint;
|
|
251
257
|
} else {
|
|
252
258
|
// Dragging
|
|
253
259
|
candidate.start = addDuration(cloneDate(event.start), delta);
|
|
@@ -255,7 +261,7 @@
|
|
|
255
261
|
candidate.resourceIds = event.resourceIds.filter(id => id !== resource.id);
|
|
256
262
|
candidate.resourceIds.push(newResource.id);
|
|
257
263
|
}
|
|
258
|
-
constraintFn =
|
|
264
|
+
constraintFn = dragConstraint;
|
|
259
265
|
}
|
|
260
266
|
}
|
|
261
267
|
// Check constraint
|
|
@@ -269,35 +275,35 @@
|
|
|
269
275
|
);
|
|
270
276
|
if (result === false) {
|
|
271
277
|
// Revert preview event
|
|
272
|
-
|
|
278
|
+
updateIEvent(event);
|
|
273
279
|
break;
|
|
274
280
|
}
|
|
275
281
|
}
|
|
276
282
|
// Update preview event
|
|
277
|
-
|
|
283
|
+
updateIEvent(candidate);
|
|
278
284
|
} while (0);
|
|
279
285
|
}
|
|
280
286
|
}
|
|
281
287
|
}
|
|
282
288
|
|
|
283
|
-
if (
|
|
289
|
+
if (dragScroll) {
|
|
284
290
|
let thresholdY = 24;
|
|
285
291
|
let thresholdX = 24;
|
|
286
292
|
animate(() => {
|
|
287
293
|
if (viewport) {
|
|
288
294
|
if (!allDaySlot) {
|
|
289
295
|
if (toY < viewport.top + thresholdY) {
|
|
290
|
-
|
|
296
|
+
mainEl.scrollTop += max(-8, (toY - viewport.top - thresholdY) / 3);
|
|
291
297
|
}
|
|
292
298
|
if (toY > viewport.bottom - thresholdY) {
|
|
293
|
-
|
|
299
|
+
mainEl.scrollTop += min(8, (toY - viewport.bottom + thresholdY) / 3);
|
|
294
300
|
}
|
|
295
301
|
}
|
|
296
302
|
if (toX < viewport.left + thresholdX) {
|
|
297
|
-
|
|
303
|
+
mainEl.scrollLeft += max(-8, (toX - viewport.left - thresholdX) / 3);
|
|
298
304
|
}
|
|
299
305
|
if (toX > viewport.right - thresholdX) {
|
|
300
|
-
|
|
306
|
+
mainEl.scrollLeft += min(8, (toX - viewport.right + thresholdX) / 3);
|
|
301
307
|
}
|
|
302
308
|
if (toY < thresholdY) {
|
|
303
309
|
window.scrollBy(0, max(-8, (toY - thresholdY) / 3));
|
|
@@ -305,7 +311,6 @@
|
|
|
305
311
|
if (toY > window.innerHeight - thresholdY) {
|
|
306
312
|
window.scrollBy(0, min(8, (toY - window.innerHeight + thresholdY) / 3));
|
|
307
313
|
}
|
|
308
|
-
|
|
309
314
|
}
|
|
310
315
|
});
|
|
311
316
|
}
|
|
@@ -327,31 +332,35 @@
|
|
|
327
332
|
}
|
|
328
333
|
|
|
329
334
|
function handlePointerUp(jsEvent) {
|
|
330
|
-
if (selected &&
|
|
335
|
+
if (selected && unselectAuto && !(unselectCancel && jsEvent.target.closest(unselectCancel))) {
|
|
331
336
|
unselect(jsEvent);
|
|
332
337
|
}
|
|
333
338
|
if (action && jsEvent.isPrimary) {
|
|
334
339
|
if (interacting) {
|
|
335
340
|
if (selecting()) {
|
|
336
341
|
selected = true;
|
|
337
|
-
if (isFunction(
|
|
338
|
-
let info = createSelectCallbackInfo(
|
|
339
|
-
|
|
342
|
+
if (isFunction(selectFn)) {
|
|
343
|
+
let info = createSelectCallbackInfo(iEvent, jsEvent);
|
|
344
|
+
selectFn(info);
|
|
340
345
|
}
|
|
341
346
|
} else {
|
|
342
347
|
event.display = display;
|
|
343
348
|
|
|
344
|
-
let callback = resizing() ?
|
|
349
|
+
let callback = resizing() ? eventResizeStop : eventDragStop;
|
|
345
350
|
if (isFunction(callback)) {
|
|
346
|
-
callback({
|
|
351
|
+
callback({
|
|
352
|
+
event: toEventWithLocalDates(event),
|
|
353
|
+
jsEvent,
|
|
354
|
+
view: toViewWithLocalDates(view)
|
|
355
|
+
});
|
|
347
356
|
}
|
|
348
357
|
|
|
349
358
|
let oldEvent = cloneEvent(event);
|
|
350
|
-
updateEvent(event,
|
|
359
|
+
updateEvent(event, iEvent);
|
|
351
360
|
|
|
352
361
|
destroyIEvent();
|
|
353
362
|
|
|
354
|
-
callback = resizing() ?
|
|
363
|
+
callback = resizing() ? eventResize : eventDrop;
|
|
355
364
|
if (isFunction(callback)) {
|
|
356
365
|
let eventRef = event;
|
|
357
366
|
let info = createCallbackInfo(event, oldEvent, jsEvent);
|
|
@@ -365,19 +374,19 @@
|
|
|
365
374
|
} else {
|
|
366
375
|
if (clicking() || selecting()) {
|
|
367
376
|
// Perform date click
|
|
368
|
-
if (isFunction(
|
|
377
|
+
if (isFunction(dateClick) && !noDateClick) {
|
|
369
378
|
toX = jsEvent.clientX;
|
|
370
379
|
toY = jsEvent.clientY;
|
|
371
380
|
let dayEl = getElementWithPayload(toX, toY);
|
|
372
381
|
if (dayEl) {
|
|
373
382
|
let {allDay, date, resource} = getPayload(dayEl)(toX, toY);
|
|
374
|
-
|
|
383
|
+
dateClick({
|
|
375
384
|
allDay,
|
|
376
385
|
date: toLocalDate(date),
|
|
377
386
|
dateStr: toISOString(date),
|
|
378
387
|
dayEl,
|
|
379
388
|
jsEvent,
|
|
380
|
-
view: toViewWithLocalDates(
|
|
389
|
+
view: toViewWithLocalDates(view),
|
|
381
390
|
resource
|
|
382
391
|
});
|
|
383
392
|
}
|
|
@@ -387,7 +396,8 @@
|
|
|
387
396
|
|
|
388
397
|
interacting = false;
|
|
389
398
|
action = fromX = fromY = toX = toY = event = display = date = newDate = resource = newResource = delta =
|
|
390
|
-
extraDuration = allDay =
|
|
399
|
+
extraDuration = allDay = minResize = selectStep = margin = gridEl = viewport = snapDuration = undefined;
|
|
400
|
+
mainState.iClass = undefined;
|
|
391
401
|
|
|
392
402
|
if (timer) {
|
|
393
403
|
clearTimeout(timer);
|
|
@@ -410,16 +420,16 @@
|
|
|
410
420
|
if (dayEl) {
|
|
411
421
|
let payload = getPayload(dayEl)(toX, toY);
|
|
412
422
|
if (payload.disabled) {
|
|
413
|
-
if (
|
|
423
|
+
if (!validRange.end || payload.date < validRange.end) {
|
|
414
424
|
return findPayload(dayEl.nextElementSibling);
|
|
415
425
|
}
|
|
416
|
-
if (
|
|
426
|
+
if (!validRange.start || payload.date > validRange.start) {
|
|
417
427
|
return findPayload(dayEl.previousElementSibling);
|
|
418
428
|
}
|
|
419
429
|
} else {
|
|
420
430
|
if (
|
|
421
431
|
(selecting() || resizing()) &&
|
|
422
|
-
payload.resource &&
|
|
432
|
+
payload.resource && !iEvent.resourceIds.includes(payload.resource.id) && !features.includes('timeline')
|
|
423
433
|
) {
|
|
424
434
|
if (toX > fromX) {
|
|
425
435
|
return findPayload(dayEl.previousElementSibling);
|
|
@@ -434,45 +444,58 @@
|
|
|
434
444
|
}
|
|
435
445
|
|
|
436
446
|
function calcViewport() {
|
|
437
|
-
let mainRect = rect(
|
|
447
|
+
let mainRect = rect(mainEl);
|
|
438
448
|
let gridRect = rect(gridEl);
|
|
439
|
-
let scaleX = mainRect.width /
|
|
440
|
-
let scaleY = mainRect.height /
|
|
449
|
+
let scaleX = mainRect.width / mainEl.offsetWidth;
|
|
450
|
+
let scaleY = mainRect.height / mainEl.offsetHeight;
|
|
441
451
|
let rtl = isRtl();
|
|
442
452
|
viewport = {
|
|
443
|
-
left: max(0, rtl
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
453
|
+
left: max(0, rtl
|
|
454
|
+
? mainRect.right - mainEl.clientWidth * scaleX
|
|
455
|
+
: gridRect.left + mainEl.scrollLeft * scaleX
|
|
456
|
+
),
|
|
457
|
+
right: min(document.documentElement.clientWidth, rtl
|
|
458
|
+
? gridRect.right + mainEl.scrollLeft * scaleX
|
|
459
|
+
: mainRect.left + mainEl.clientWidth * scaleX
|
|
460
|
+
) - 2,
|
|
461
|
+
top: max(0, gridRect.top + (!allDaySlot ? mainEl.scrollTop : 0) * scaleY),
|
|
462
|
+
bottom: min(document.documentElement.clientHeight, !allDaySlot
|
|
463
|
+
? mainRect.top + mainEl.clientHeight * scaleY
|
|
464
|
+
: gridRect.bottom
|
|
465
|
+
) - 2
|
|
447
466
|
};
|
|
448
467
|
}
|
|
449
468
|
|
|
450
469
|
function createIEvent(jsEvent, callback) {
|
|
451
470
|
if (isFunction(callback)) {
|
|
452
|
-
callback({
|
|
471
|
+
callback({
|
|
472
|
+
event: toEventWithLocalDates(event),
|
|
473
|
+
jsEvent,
|
|
474
|
+
view: toViewWithLocalDates(view)
|
|
475
|
+
});
|
|
453
476
|
}
|
|
454
477
|
display = event.display;
|
|
455
478
|
event.display = 'preview';
|
|
456
|
-
|
|
479
|
+
iEvent = cloneEvent(event);
|
|
457
480
|
if (margin !== undefined) {
|
|
458
|
-
|
|
481
|
+
iEvent._margin = margin;
|
|
459
482
|
}
|
|
460
483
|
if (extraDuration) {
|
|
461
|
-
addDuration(
|
|
484
|
+
addDuration(iEvent.end, extraDuration);
|
|
462
485
|
}
|
|
463
486
|
event.display = 'ghost';
|
|
464
|
-
|
|
487
|
+
mainState.events = [...events];
|
|
465
488
|
}
|
|
466
489
|
|
|
467
490
|
function createIEventSelect() {
|
|
468
|
-
|
|
491
|
+
iEvent = {
|
|
469
492
|
id: '{select}',
|
|
470
493
|
allDay: event.allDay,
|
|
471
494
|
start: event.start,
|
|
472
495
|
title: '',
|
|
473
496
|
display: 'preview',
|
|
474
497
|
extendedProps: {},
|
|
475
|
-
backgroundColor:
|
|
498
|
+
backgroundColor: selectBackgroundColor,
|
|
476
499
|
resourceIds: event.resourceIds,
|
|
477
500
|
classNames: [],
|
|
478
501
|
styles: []
|
|
@@ -480,19 +503,25 @@
|
|
|
480
503
|
}
|
|
481
504
|
|
|
482
505
|
function destroyIEvent() {
|
|
483
|
-
|
|
506
|
+
iEvent = undefined;
|
|
507
|
+
iEvents.delete('action');
|
|
484
508
|
}
|
|
485
509
|
|
|
486
510
|
function copyIEventData(target, source) {
|
|
487
511
|
target.start = source.start;
|
|
488
512
|
target.end = source.end;
|
|
489
513
|
target.resourceIds = source.resourceIds;
|
|
490
|
-
return target;
|
|
514
|
+
return {...target};
|
|
491
515
|
}
|
|
492
516
|
|
|
493
517
|
function updateEvent(target, source) {
|
|
494
518
|
copyIEventData(target, source);
|
|
495
|
-
|
|
519
|
+
mainState.events = [...events];
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function updateIEvent(source) {
|
|
523
|
+
iEvent = copyIEventData(iEvent, source);
|
|
524
|
+
iEvents.set('action', iEvent);
|
|
496
525
|
}
|
|
497
526
|
|
|
498
527
|
function createSelectCallbackInfo(event, jsEvent) {
|
|
@@ -503,7 +532,7 @@
|
|
|
503
532
|
startStr: toISOString(event.start),
|
|
504
533
|
endStr: toISOString(event.end),
|
|
505
534
|
allDay,
|
|
506
|
-
view: toViewWithLocalDates(
|
|
535
|
+
view: toViewWithLocalDates(view),
|
|
507
536
|
resource,
|
|
508
537
|
jsEvent
|
|
509
538
|
};
|
|
@@ -525,7 +554,7 @@
|
|
|
525
554
|
assign(info, {
|
|
526
555
|
event: toEventWithLocalDates(event),
|
|
527
556
|
oldEvent: toEventWithLocalDates(oldEvent),
|
|
528
|
-
view: toViewWithLocalDates(
|
|
557
|
+
view: toViewWithLocalDates(view),
|
|
529
558
|
jsEvent
|
|
530
559
|
});
|
|
531
560
|
|
|
@@ -568,22 +597,25 @@
|
|
|
568
597
|
if (selected) {
|
|
569
598
|
selected = false;
|
|
570
599
|
destroyIEvent();
|
|
571
|
-
if (isFunction(
|
|
572
|
-
|
|
600
|
+
if (isFunction(unselectFn)) {
|
|
601
|
+
unselectFn({
|
|
573
602
|
jsEvent,
|
|
574
|
-
view: toViewWithLocalDates(
|
|
603
|
+
view: toViewWithLocalDates(view)
|
|
575
604
|
});
|
|
576
605
|
}
|
|
577
606
|
}
|
|
578
607
|
}
|
|
579
608
|
|
|
609
|
+
// Clear selection when view changes
|
|
610
|
+
$effect.pre(() => {
|
|
611
|
+
view;
|
|
612
|
+
unselect();
|
|
613
|
+
});
|
|
614
|
+
|
|
580
615
|
export function noClick() {
|
|
581
616
|
noDateClick = true;
|
|
582
617
|
}
|
|
583
618
|
|
|
584
|
-
// Clear selection on view params change
|
|
585
|
-
_view.subscribe(unselect);
|
|
586
|
-
|
|
587
619
|
function handleTouchStart(jsEvent) {
|
|
588
620
|
if (complexAction()) {
|
|
589
621
|
let target = jsEvent.target;
|
|
@@ -1,49 +1,20 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import {getContext} from 'svelte';
|
|
3
|
-
import
|
|
4
|
-
import {eventDraggable} from './lib';
|
|
3
|
+
import AuxState from './state.svelte.js';
|
|
5
4
|
import Action from './Action.svelte';
|
|
6
5
|
import Pointer from './Pointer.svelte';
|
|
7
6
|
import Resizer from './Resizer.svelte';
|
|
8
7
|
|
|
9
|
-
let
|
|
10
|
-
|
|
8
|
+
let mainState = getContext('state');
|
|
9
|
+
new AuxState(mainState);
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
let {interaction, options: {pointer}} = $derived(mainState);
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
$eventStartEditable;
|
|
17
|
-
$editable;
|
|
18
|
-
$_iClasses = (classNames, event) => {
|
|
19
|
-
let {display} = event;
|
|
20
|
-
return [
|
|
21
|
-
...classNames,
|
|
22
|
-
helperEvent(display)
|
|
23
|
-
? [$theme[display]]
|
|
24
|
-
: (
|
|
25
|
-
!bgEvent(display) && eventDraggable(event, $eventStartEditable, $editable)
|
|
26
|
-
? [$theme.draggable]
|
|
27
|
-
: []
|
|
28
|
-
)
|
|
29
|
-
];
|
|
30
|
-
};
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
$effect(() => {
|
|
34
|
-
if ($_mainEl) {
|
|
35
|
-
return listen($_mainEl, 'scroll', mainElScrollHandler);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
function mainElScrollHandler() {
|
|
40
|
-
for (let component of Object.values($_interaction)) {
|
|
41
|
-
component?.handleScroll?.();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
13
|
+
// svelte-ignore state_referenced_locally
|
|
14
|
+
interaction.resizer = Resizer;
|
|
44
15
|
</script>
|
|
45
16
|
|
|
46
|
-
<Action bind:this={
|
|
47
|
-
{#if
|
|
48
|
-
<Pointer bind:this={
|
|
17
|
+
<Action bind:this={interaction.action}/>
|
|
18
|
+
{#if pointer}
|
|
19
|
+
<Pointer bind:this={interaction.pointer}/>
|
|
49
20
|
{/if}
|
|
@@ -2,29 +2,25 @@
|
|
|
2
2
|
import {getContext} from 'svelte';
|
|
3
3
|
import {addDuration, cloneDate, getElementWithPayload, getPayload} from '#lib';
|
|
4
4
|
|
|
5
|
-
let {
|
|
5
|
+
let {iEvents, options: {slotDuration}} = $derived(getContext('state'));
|
|
6
6
|
|
|
7
7
|
let x = 0, y = 0;
|
|
8
|
-
|
|
9
|
-
$effect(() => {
|
|
10
|
-
if ($_iEvents[0]) {
|
|
11
|
-
removePointerEvent();
|
|
12
|
-
}
|
|
13
|
-
});
|
|
8
|
+
let iEvent;
|
|
14
9
|
|
|
15
10
|
function move() {
|
|
16
11
|
let dayEl = getElementWithPayload(x, y);
|
|
17
12
|
|
|
18
|
-
if (dayEl) {
|
|
13
|
+
if (dayEl && !iEvents.has('action')) {
|
|
19
14
|
let {allDay, date, resource, disabled} = getPayload(dayEl)(x, y);
|
|
20
15
|
if (!disabled) {
|
|
21
|
-
if (
|
|
16
|
+
if (!iEvent) {
|
|
22
17
|
createPointerEvent();
|
|
23
18
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
iEvent.allDay = allDay;
|
|
20
|
+
iEvent.start = date;
|
|
21
|
+
iEvent.end = addDuration(cloneDate(date), slotDuration);
|
|
22
|
+
iEvent.resourceIds = resource ? [resource.id] : [];
|
|
23
|
+
iEvents.set('pointer', {...iEvent});
|
|
28
24
|
|
|
29
25
|
return;
|
|
30
26
|
}
|
|
@@ -46,7 +42,7 @@
|
|
|
46
42
|
}
|
|
47
43
|
|
|
48
44
|
function createPointerEvent() {
|
|
49
|
-
|
|
45
|
+
iEvent = {
|
|
50
46
|
id: '{pointer}',
|
|
51
47
|
title: '',
|
|
52
48
|
display: 'pointer',
|
|
@@ -58,9 +54,8 @@
|
|
|
58
54
|
}
|
|
59
55
|
|
|
60
56
|
function removePointerEvent() {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
57
|
+
iEvent = undefined;
|
|
58
|
+
iEvents.delete('pointer');
|
|
64
59
|
}
|
|
65
60
|
|
|
66
61
|
function validEvent(jsEvent) {
|