@event-calendar/core 1.1.1 → 1.2.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 +2 -2
- package/index.js +646 -8
- package/package.json +2 -3
- package/src/Auxiliary.svelte +1 -1
- package/src/Buttons.svelte +1 -1
- package/src/Calendar.svelte +1 -1
- package/src/index.js +2 -1
- package/src/lib/actions.js +43 -0
- package/src/lib/date.js +219 -0
- package/src/lib/debounce.js +10 -0
- package/src/lib/dom.js +53 -0
- package/src/lib/events.js +224 -0
- package/src/lib/stores.js +54 -0
- package/src/lib/utils.js +23 -0
- package/src/lib/view.js +24 -0
- package/src/lib.js +8 -0
- package/src/storage/options.js +1 -2
- package/src/storage/state.js +1 -2
- package/src/storage/stores.js +5 -5
package/README.md
CHANGED
|
@@ -193,8 +193,8 @@ import '@event-calendar/core/index.css';
|
|
|
193
193
|
### Pre-built browser ready bundle
|
|
194
194
|
Include the following lines of code in the `<head>` section of your page:
|
|
195
195
|
```html
|
|
196
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@event-calendar/build@1.
|
|
197
|
-
<script src="https://cdn.jsdelivr.net/npm/@event-calendar/build@1.
|
|
196
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@event-calendar/build@1.2.0/event-calendar.min.css">
|
|
197
|
+
<script src="https://cdn.jsdelivr.net/npm/@event-calendar/build@1.2.0/event-calendar.min.js"></script>
|
|
198
198
|
```
|
|
199
199
|
|
|
200
200
|
<details>
|
package/index.js
CHANGED
|
@@ -1,7 +1,645 @@
|
|
|
1
|
-
import { is_function, noop, identity, tick, SvelteComponent, init, safe_not_equal, empty, insert, destroy_each, detach, component_subscribe, set_store_value, element, text, attr, append, listen, set_data, transition_in, group_outros, check_outros, transition_out, space, create_component, mount_component, destroy_component, construct_svelte_component, set_style, get_current_component } from 'svelte/internal';
|
|
1
|
+
import { run_all, is_function, noop, identity, tick, SvelteComponent, init, safe_not_equal, empty, insert, destroy_each, detach, component_subscribe, set_store_value, element, text, attr, append, listen, set_data, transition_in, group_outros, check_outros, transition_out, space, create_component, mount_component, destroy_component, construct_svelte_component, set_style, get_current_component } from 'svelte/internal';
|
|
2
2
|
import { getContext, setContext, beforeUpdate } from 'svelte';
|
|
3
|
-
import { derived,
|
|
4
|
-
|
|
3
|
+
import { writable, derived, get, readable } from 'svelte/store';
|
|
4
|
+
|
|
5
|
+
function assign(...args) {
|
|
6
|
+
return Object.assign(...args);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function floor(value) {
|
|
10
|
+
return Math.floor(value);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function min(...args) {
|
|
14
|
+
return Math.min(...args);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function max(...args) {
|
|
18
|
+
return Math.max(...args);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isObject(test) {
|
|
22
|
+
return typeof test === 'object' && test !== null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function symbol() {
|
|
26
|
+
return Symbol('ec');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function setContent(node, content) {
|
|
30
|
+
let actions = {
|
|
31
|
+
update(content) {
|
|
32
|
+
while (node.firstChild) {
|
|
33
|
+
node.removeChild(node.lastChild);
|
|
34
|
+
}
|
|
35
|
+
if (!isObject(content)) {
|
|
36
|
+
node.innerText = content;
|
|
37
|
+
} else if (content.domNodes) {
|
|
38
|
+
for (let child of content.domNodes) {
|
|
39
|
+
node.appendChild(child);
|
|
40
|
+
}
|
|
41
|
+
} else if (content.html) {
|
|
42
|
+
node.innerHTML = content.html;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
actions.update(content);
|
|
47
|
+
|
|
48
|
+
return actions;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Dispatch event occurred outside of node */
|
|
52
|
+
function outsideEvent(node, type) {
|
|
53
|
+
|
|
54
|
+
const handlePointerDown = jsEvent => {
|
|
55
|
+
if (node && !node.contains(jsEvent.target)) {
|
|
56
|
+
node.dispatchEvent(
|
|
57
|
+
new CustomEvent(type + 'outside', {detail: {jsEvent}})
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
document.addEventListener(type, handlePointerDown, true);
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
destroy() {
|
|
66
|
+
document.removeEventListener(type, handlePointerDown, true);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const DAY_IN_SECONDS = 86400;
|
|
72
|
+
|
|
73
|
+
function createDate(input = undefined) {
|
|
74
|
+
if (input !== undefined) {
|
|
75
|
+
return input instanceof Date ? _fromLocalDate(input) : _fromISOString(input);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return _fromLocalDate(new Date());
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function createDuration(input) {
|
|
82
|
+
if (typeof input === 'number') {
|
|
83
|
+
input = {seconds: input};
|
|
84
|
+
} else if (typeof input === 'string') {
|
|
85
|
+
// Expected format hh[:mm[:ss]]
|
|
86
|
+
let seconds = 0, exp = 2;
|
|
87
|
+
for (let part of input.split(':', 3)) {
|
|
88
|
+
seconds += parseInt(part, 10) * Math.pow(60, exp--);
|
|
89
|
+
}
|
|
90
|
+
input = {seconds};
|
|
91
|
+
} else if (input instanceof Date) {
|
|
92
|
+
input = {hours: input.getUTCHours(), minutes: input.getUTCMinutes(), seconds: input.getUTCSeconds()};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let weeks = input.weeks || input.week || 0;
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
years: input.years || input.year || 0,
|
|
99
|
+
months: input.months || input.month || 0,
|
|
100
|
+
days: weeks * 7 + (input.days || input.day || 0),
|
|
101
|
+
seconds: (input.hours || input.hour || 0) * 60 * 60 +
|
|
102
|
+
(input.minutes || input.minute || 0) * 60 +
|
|
103
|
+
(input.seconds || input.second || 0),
|
|
104
|
+
inWeeks: !!weeks
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function cloneDate(date) {
|
|
109
|
+
return new Date(date.getTime());
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function addDuration(date, duration, x = 1) {
|
|
113
|
+
date.setUTCFullYear(date.getUTCFullYear() + x * duration.years);
|
|
114
|
+
let month = date.getUTCMonth() + x * duration.months;
|
|
115
|
+
date.setUTCMonth(month);
|
|
116
|
+
month %= 12;
|
|
117
|
+
if (month < 0) {
|
|
118
|
+
month += 12;
|
|
119
|
+
}
|
|
120
|
+
while (date.getUTCMonth() !== month) {
|
|
121
|
+
subtractDay(date);
|
|
122
|
+
}
|
|
123
|
+
date.setUTCDate(date.getUTCDate() + x * duration.days);
|
|
124
|
+
date.setUTCSeconds(date.getUTCSeconds() + x * duration.seconds);
|
|
125
|
+
|
|
126
|
+
return date;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function subtractDuration(date, duration, x = 1) {
|
|
130
|
+
return addDuration(date, duration, -x);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function addDay(date, x = 1) {
|
|
134
|
+
date.setUTCDate(date.getUTCDate() + x);
|
|
135
|
+
|
|
136
|
+
return date;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function subtractDay(date, x = 1) {
|
|
140
|
+
return addDay(date, -x);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function setMidnight(date) {
|
|
144
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
145
|
+
|
|
146
|
+
return date;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function toLocalDate(date) {
|
|
150
|
+
return new Date(
|
|
151
|
+
date.getUTCFullYear(),
|
|
152
|
+
date.getUTCMonth(),
|
|
153
|
+
date.getUTCDate(),
|
|
154
|
+
date.getUTCHours(),
|
|
155
|
+
date.getUTCMinutes(),
|
|
156
|
+
date.getUTCSeconds()
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function toISOString(date) {
|
|
161
|
+
return date.toISOString().substring(0, 19);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function formatRange(start, end, intl) {
|
|
165
|
+
if (start.getFullYear() !== end.getFullYear()) {
|
|
166
|
+
return intl.format(start) + ' - ' + intl.format(end);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
let diff = [];
|
|
170
|
+
if (start.getMonth() !== end.getMonth()) {
|
|
171
|
+
diff.push('month');
|
|
172
|
+
}
|
|
173
|
+
if (start.getDate() !== end.getDate()) {
|
|
174
|
+
diff.push('day');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (!diff.length) {
|
|
178
|
+
return intl.format(start);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
let opts1 = intl.resolvedOptions();
|
|
182
|
+
let opts2 = {};
|
|
183
|
+
for (let key of diff) {
|
|
184
|
+
opts2[key] = opts1[key];
|
|
185
|
+
}
|
|
186
|
+
let intl2 = new Intl.DateTimeFormat(opts1.locale, opts2);
|
|
187
|
+
|
|
188
|
+
let full1 = intl.format(start);
|
|
189
|
+
let full2 = intl.format(end);
|
|
190
|
+
let part1 = intl2.format(start);
|
|
191
|
+
let part2 = intl2.format(end);
|
|
192
|
+
|
|
193
|
+
let common = _commonChunks(full1, part1, full2, part2);
|
|
194
|
+
if (common) {
|
|
195
|
+
return common.head + part1 + ' - ' + part2 + common.tail;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return full1 + ' - ' + full2;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function datesEqual(date1, ...dates2) {
|
|
202
|
+
return dates2.every(date2 => date1.getTime() === date2.getTime());
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function nextClosestDay(date, day) {
|
|
206
|
+
let diff = day - date.getUTCDay();
|
|
207
|
+
date.setUTCDate(date.getUTCDate() + (diff >= 0 ? diff : diff + 7));
|
|
208
|
+
return date;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function prevClosestDay(date, day) {
|
|
212
|
+
let diff = day - date.getUTCDay();
|
|
213
|
+
date.setUTCDate(date.getUTCDate() + (diff <= 0 ? diff : diff - 7));
|
|
214
|
+
return date;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Check whether given date is string which contains no time part
|
|
219
|
+
*/
|
|
220
|
+
function noTimePart(date) {
|
|
221
|
+
return typeof date === 'string' && date.length <= 10;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Private functions
|
|
226
|
+
*/
|
|
227
|
+
|
|
228
|
+
function _fromLocalDate(date) {
|
|
229
|
+
return new Date(Date.UTC(
|
|
230
|
+
date.getFullYear(),
|
|
231
|
+
date.getMonth(),
|
|
232
|
+
date.getDate(),
|
|
233
|
+
date.getHours(),
|
|
234
|
+
date.getMinutes(),
|
|
235
|
+
date.getSeconds()
|
|
236
|
+
));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function _fromISOString(str) {
|
|
240
|
+
const parts = str.match(/\d+/g);
|
|
241
|
+
return new Date(Date.UTC(
|
|
242
|
+
Number(parts[0]),
|
|
243
|
+
Number(parts[1]) - 1,
|
|
244
|
+
Number(parts[2]),
|
|
245
|
+
Number(parts[3] || 0),
|
|
246
|
+
Number(parts[4] || 0),
|
|
247
|
+
Number(parts[5] || 0)
|
|
248
|
+
));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function _commonChunks(str1, substr1, str2, substr2) {
|
|
252
|
+
let i = 0;
|
|
253
|
+
while (i < str1.length) {
|
|
254
|
+
let res1;
|
|
255
|
+
[i, res1] = _cut(str1, substr1, i);
|
|
256
|
+
if (!res1) {
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
let j = 0;
|
|
261
|
+
while (j < str2.length) {
|
|
262
|
+
let res2;
|
|
263
|
+
[j, res2] = _cut(str2, substr2, j);
|
|
264
|
+
if (!res2) {
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (res1.head === res2.head && res1.tail === res2.tail) {
|
|
269
|
+
return res1;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return null
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function _cut(str, substr, from) {
|
|
278
|
+
let start = str.indexOf(substr, from);
|
|
279
|
+
if (start >= 0) {
|
|
280
|
+
let end = start + substr.length;
|
|
281
|
+
|
|
282
|
+
return [end, {
|
|
283
|
+
head: str.substr(0, start),
|
|
284
|
+
tail: str.substr(end)
|
|
285
|
+
}];
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return [-1, null];
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function debounce(fn, handle, queueStore) {
|
|
292
|
+
queueStore.update(queue => queue.set(handle, fn));
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function flushDebounce(queue) {
|
|
296
|
+
run_all(queue);
|
|
297
|
+
queue.clear();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function createElement(tag, className, html, text) {
|
|
301
|
+
let el = document.createElement(tag);
|
|
302
|
+
el.className = className;
|
|
303
|
+
if (html) {
|
|
304
|
+
el.innerHTML = html;
|
|
305
|
+
} else if (text) {
|
|
306
|
+
el.innerText = text;
|
|
307
|
+
}
|
|
308
|
+
return el;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function hasYScroll(el) {
|
|
312
|
+
return el.scrollHeight > el.clientHeight;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function rect(el) {
|
|
316
|
+
return el.getBoundingClientRect();
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function ancestor(el, up) {
|
|
320
|
+
while (up--) {
|
|
321
|
+
el = el.parentElement;
|
|
322
|
+
}
|
|
323
|
+
return el;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function height(el) {
|
|
327
|
+
return rect(el).height;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
let payloadProp = symbol();
|
|
331
|
+
function setPayload(el, payload) {
|
|
332
|
+
el[payloadProp] = payload;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function hasPayload(el) {
|
|
336
|
+
return !!el?.[payloadProp];
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function getPayload(el) {
|
|
340
|
+
return el[payloadProp];
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function getElementWithPayload(x, y) {
|
|
344
|
+
for (let el of document.elementsFromPoint(x, y)) {
|
|
345
|
+
if (hasPayload(el)) {
|
|
346
|
+
return el;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function createView(view, _viewTitle, _currentRange, _activeRange) {
|
|
353
|
+
return {
|
|
354
|
+
type: view,
|
|
355
|
+
title: _viewTitle,
|
|
356
|
+
currentStart: _currentRange.start,
|
|
357
|
+
currentEnd: _currentRange.end,
|
|
358
|
+
activeStart: _activeRange.start,
|
|
359
|
+
activeEnd: _activeRange.end,
|
|
360
|
+
calendar: undefined
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function toViewWithLocalDates(view) {
|
|
365
|
+
view = assign({}, view);
|
|
366
|
+
view.currentStart = toLocalDate(view.currentStart);
|
|
367
|
+
view.currentEnd = toLocalDate(view.currentEnd);
|
|
368
|
+
view.activeStart = toLocalDate(view.activeStart);
|
|
369
|
+
view.activeEnd = toLocalDate(view.activeEnd);
|
|
370
|
+
|
|
371
|
+
return view;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
let eventId = 1;
|
|
375
|
+
function createEvents(input) {
|
|
376
|
+
return input.map(event => ({
|
|
377
|
+
id: 'id' in event ? String(event.id) : `{generated-${eventId++}}`,
|
|
378
|
+
resourceIds: Array.isArray(event.resourceIds)
|
|
379
|
+
? event.resourceIds.map(String)
|
|
380
|
+
: ('resourceId' in event ? [String(event.resourceId)] : []),
|
|
381
|
+
allDay: event.allDay ?? (noTimePart(event.start) && noTimePart(event.end)),
|
|
382
|
+
start: createDate(event.start),
|
|
383
|
+
end: createDate(event.end),
|
|
384
|
+
title: event.title || '',
|
|
385
|
+
titleHTML: event.titleHTML || '',
|
|
386
|
+
editable: event.editable,
|
|
387
|
+
startEditable: event.startEditable,
|
|
388
|
+
durationEditable: event.durationEditable,
|
|
389
|
+
display: event.display || 'auto',
|
|
390
|
+
extendedProps: event.extendedProps || {},
|
|
391
|
+
backgroundColor: event.backgroundColor || event.color,
|
|
392
|
+
textColor: event.textColor
|
|
393
|
+
}));
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function createEventSources(input) {
|
|
397
|
+
return input.map(source => ({
|
|
398
|
+
events: source.events,
|
|
399
|
+
url: (source.url && source.url.trimEnd('&')) || '',
|
|
400
|
+
method: (source.method && source.method.toUpperCase()) || 'GET',
|
|
401
|
+
extraParams: source.extraParams || {}
|
|
402
|
+
}));
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function createEventChunk(event, start, end) {
|
|
406
|
+
return {
|
|
407
|
+
start: event.start > start ? event.start : start,
|
|
408
|
+
end: event.end < end ? event.end : end,
|
|
409
|
+
event
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function sortEventChunks(chunks) {
|
|
414
|
+
// Sort by start date
|
|
415
|
+
chunks.sort((a, b) => {
|
|
416
|
+
if (a.start < b.start) {
|
|
417
|
+
return -1;
|
|
418
|
+
}
|
|
419
|
+
if (a.start > b.start) {
|
|
420
|
+
return 1;
|
|
421
|
+
}
|
|
422
|
+
return 0;
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Prepare event chunks for month view and all-day slot in week view
|
|
428
|
+
*/
|
|
429
|
+
function prepareEventChunks(chunks, hiddenDays) {
|
|
430
|
+
let longChunks = {};
|
|
431
|
+
|
|
432
|
+
if (chunks.length) {
|
|
433
|
+
sortEventChunks(chunks);
|
|
434
|
+
|
|
435
|
+
let prevChunk;
|
|
436
|
+
for (let chunk of chunks) {
|
|
437
|
+
let dates = [];
|
|
438
|
+
let date = setMidnight(cloneDate(chunk.start));
|
|
439
|
+
while (chunk.end > date) {
|
|
440
|
+
if (!hiddenDays.includes(date.getUTCDay())) {
|
|
441
|
+
dates.push(cloneDate(date));
|
|
442
|
+
if (dates.length > 1) {
|
|
443
|
+
let key = date.getTime();
|
|
444
|
+
if (longChunks[key]) {
|
|
445
|
+
longChunks[key].chunks.push(chunk);
|
|
446
|
+
} else {
|
|
447
|
+
longChunks[key] = {
|
|
448
|
+
sorted: false,
|
|
449
|
+
chunks: [chunk]
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
addDay(date);
|
|
455
|
+
}
|
|
456
|
+
if (dates.length) {
|
|
457
|
+
chunk.date = dates[0];
|
|
458
|
+
chunk.days = dates.length;
|
|
459
|
+
chunk.dates = dates;
|
|
460
|
+
if (chunk.start < dates[0]) {
|
|
461
|
+
chunk.start = dates[0];
|
|
462
|
+
}
|
|
463
|
+
if (setMidnight(cloneDate(chunk.end)) > dates[dates.length - 1]) {
|
|
464
|
+
chunk.end = dates[dates.length - 1];
|
|
465
|
+
}
|
|
466
|
+
} else {
|
|
467
|
+
chunk.date = setMidnight(cloneDate(chunk.start));
|
|
468
|
+
chunk.days = 1;
|
|
469
|
+
chunk.dates = [chunk.date];
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
if (prevChunk && datesEqual(prevChunk.date, chunk.date)) {
|
|
473
|
+
chunk.prev = prevChunk;
|
|
474
|
+
}
|
|
475
|
+
prevChunk = chunk;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
return longChunks;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function repositionEvent(chunk, longChunks, height) {
|
|
483
|
+
chunk.top = 0;
|
|
484
|
+
if (chunk.prev) {
|
|
485
|
+
chunk.top = chunk.prev.bottom + 1;
|
|
486
|
+
}
|
|
487
|
+
chunk.bottom = chunk.top + height;
|
|
488
|
+
let margin = 1;
|
|
489
|
+
let key = chunk.date.getTime();
|
|
490
|
+
if (longChunks[key]) {
|
|
491
|
+
if (!longChunks[key].sorted) {
|
|
492
|
+
longChunks[key].chunks.sort((a, b) => a.top - b.top);
|
|
493
|
+
longChunks[key].sorted = true;
|
|
494
|
+
}
|
|
495
|
+
for (let longChunk of longChunks[key].chunks) {
|
|
496
|
+
if (chunk.top < longChunk.bottom && chunk.bottom > longChunk.top) {
|
|
497
|
+
let offset = longChunk.bottom - chunk.top + 1;
|
|
498
|
+
margin += offset;
|
|
499
|
+
chunk.top += offset;
|
|
500
|
+
chunk.bottom += offset;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
return margin;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function createEventContent(chunk, displayEventEnd, eventContent, theme, _intlEventTime, _view) {
|
|
509
|
+
let timeText = _intlEventTime.format(chunk.start), content;
|
|
510
|
+
if (displayEventEnd && chunk.event.display !== 'pointer') {
|
|
511
|
+
timeText += ` - ${_intlEventTime.format(chunk.end)}`;
|
|
512
|
+
}
|
|
513
|
+
if (eventContent) {
|
|
514
|
+
content = is_function(eventContent)
|
|
515
|
+
? eventContent({
|
|
516
|
+
event: toEventWithLocalDates(chunk.event),
|
|
517
|
+
timeText,
|
|
518
|
+
view: toViewWithLocalDates(_view)
|
|
519
|
+
})
|
|
520
|
+
: eventContent;
|
|
521
|
+
} else {
|
|
522
|
+
switch (chunk.event.display) {
|
|
523
|
+
case 'background':
|
|
524
|
+
content = '';
|
|
525
|
+
break;
|
|
526
|
+
case 'pointer':
|
|
527
|
+
content = {
|
|
528
|
+
domNodes: [createElement('div', theme.eventTime, null, timeText)]
|
|
529
|
+
};
|
|
530
|
+
break;
|
|
531
|
+
default:
|
|
532
|
+
content = {
|
|
533
|
+
domNodes: [
|
|
534
|
+
createElement('div', theme.eventTime, null, timeText),
|
|
535
|
+
createElement('div', theme.eventTitle, chunk.event.titleHTML, chunk.event.title)
|
|
536
|
+
]
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
return [timeText, content];
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
function toEventWithLocalDates(event) {
|
|
545
|
+
return _cloneEvent(event, toLocalDate);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function cloneEvent(event) {
|
|
549
|
+
return _cloneEvent(event, cloneDate);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function _cloneEvent(event, dateFn) {
|
|
553
|
+
event = assign({}, event);
|
|
554
|
+
event.start = dateFn(event.start);
|
|
555
|
+
event.end = dateFn(event.end);
|
|
556
|
+
|
|
557
|
+
return event;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Check whether the event intersects with the given date range and resource
|
|
562
|
+
* @param event
|
|
563
|
+
* @param start
|
|
564
|
+
* @param end
|
|
565
|
+
* @param [resource]
|
|
566
|
+
* @param [timeMode] Zero-length events should be allowed (@see https://github.com/vkurko/calendar/issues/50), except in time mode
|
|
567
|
+
* @return boolean
|
|
568
|
+
*/
|
|
569
|
+
function eventIntersects(event, start, end, resource, timeMode) {
|
|
570
|
+
return (
|
|
571
|
+
event.start < end && event.end > start || !timeMode && datesEqual(event.start, event.end, start)
|
|
572
|
+
) && (
|
|
573
|
+
resource === undefined || event.resourceIds.includes(resource.id)
|
|
574
|
+
);
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
function helperEvent(display) {
|
|
578
|
+
return display === 'preview' || display === 'ghost' || display === 'pointer';
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function bgEvent(display) {
|
|
582
|
+
return display === 'background';
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
function previewEvent(display) {
|
|
586
|
+
return display === 'preview';
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
function ghostEvent(display) {
|
|
590
|
+
return display === 'ghost';
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
function writable2(value, parser, start) {
|
|
594
|
+
return {
|
|
595
|
+
...writable(parser ? parser(value) : value, start),
|
|
596
|
+
parse: parser
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
function derived2(stores, fn, initValue) {
|
|
601
|
+
let storeValue = initValue;
|
|
602
|
+
let hasSubscribers = false;
|
|
603
|
+
let auto = fn.length < 2;
|
|
604
|
+
let fn2 = (_, set) => {
|
|
605
|
+
hasSubscribers = true;
|
|
606
|
+
if (auto) {
|
|
607
|
+
storeValue = fn(_, set);
|
|
608
|
+
set(storeValue);
|
|
609
|
+
} else {
|
|
610
|
+
fn(_, value => {storeValue = value; set(value);});
|
|
611
|
+
}
|
|
612
|
+
return () => {hasSubscribers = false;};
|
|
613
|
+
};
|
|
614
|
+
let store = derived(stores, fn2, storeValue);
|
|
615
|
+
return {
|
|
616
|
+
...store,
|
|
617
|
+
get: () => hasSubscribers ? storeValue : get(store)
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
function intl(locale, format) {
|
|
622
|
+
return derived([locale, format], ([$locale, $format]) => {
|
|
623
|
+
let intl = is_function($format)
|
|
624
|
+
? {format: $format}
|
|
625
|
+
: new Intl.DateTimeFormat($locale, $format);
|
|
626
|
+
return {
|
|
627
|
+
format: date => intl.format(toLocalDate(date))
|
|
628
|
+
};
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function intlRange(locale, format) {
|
|
633
|
+
return derived([locale, format], ([$locale, $format]) => {
|
|
634
|
+
if (is_function($format)) {
|
|
635
|
+
return {format: (start, end) => $format(toLocalDate(start), toLocalDate(end))};
|
|
636
|
+
}
|
|
637
|
+
let intl = new Intl.DateTimeFormat($locale, $format);
|
|
638
|
+
return {
|
|
639
|
+
format: (start, end) => formatRange(toLocalDate(start), toLocalDate(end), intl)
|
|
640
|
+
};
|
|
641
|
+
});
|
|
642
|
+
}
|
|
5
643
|
|
|
6
644
|
function createOptions(plugins) {
|
|
7
645
|
let options = {
|
|
@@ -455,7 +1093,7 @@ function parseOpts(opts, state) {
|
|
|
455
1093
|
}
|
|
456
1094
|
}
|
|
457
1095
|
|
|
458
|
-
/* packages/core/src/Buttons.svelte generated by Svelte v3.
|
|
1096
|
+
/* packages/core/src/Buttons.svelte generated by Svelte v3.59.1 */
|
|
459
1097
|
|
|
460
1098
|
function get_each_context$2(ctx, list, i) {
|
|
461
1099
|
const child_ctx = ctx.slice();
|
|
@@ -860,7 +1498,7 @@ class Buttons extends SvelteComponent {
|
|
|
860
1498
|
}
|
|
861
1499
|
}
|
|
862
1500
|
|
|
863
|
-
/* packages/core/src/Toolbar.svelte generated by Svelte v3.
|
|
1501
|
+
/* packages/core/src/Toolbar.svelte generated by Svelte v3.59.1 */
|
|
864
1502
|
|
|
865
1503
|
function get_each_context$1(ctx, list, i) {
|
|
866
1504
|
const child_ctx = ctx.slice();
|
|
@@ -1234,7 +1872,7 @@ class Toolbar extends SvelteComponent {
|
|
|
1234
1872
|
}
|
|
1235
1873
|
}
|
|
1236
1874
|
|
|
1237
|
-
/* packages/core/src/Auxiliary.svelte generated by Svelte v3.
|
|
1875
|
+
/* packages/core/src/Auxiliary.svelte generated by Svelte v3.59.1 */
|
|
1238
1876
|
|
|
1239
1877
|
function get_each_context(ctx, list, i) {
|
|
1240
1878
|
const child_ctx = ctx.slice();
|
|
@@ -1436,7 +2074,7 @@ class Auxiliary extends SvelteComponent {
|
|
|
1436
2074
|
}
|
|
1437
2075
|
}
|
|
1438
2076
|
|
|
1439
|
-
/* packages/core/src/Calendar.svelte generated by Svelte v3.
|
|
2077
|
+
/* packages/core/src/Calendar.svelte generated by Svelte v3.59.1 */
|
|
1440
2078
|
|
|
1441
2079
|
function create_fragment(ctx) {
|
|
1442
2080
|
let div;
|
|
@@ -1824,4 +2462,4 @@ class Calendar extends SvelteComponent {
|
|
|
1824
2462
|
}
|
|
1825
2463
|
}
|
|
1826
2464
|
|
|
1827
|
-
export { Calendar as default };
|
|
2465
|
+
export { DAY_IN_SECONDS, addDay, addDuration, ancestor, assign, bgEvent, cloneDate, cloneEvent, createDate, createDuration, createElement, createEventChunk, createEventContent, createEventSources, createEvents, createView, datesEqual, debounce, Calendar as default, derived2, eventIntersects, floor, flushDebounce, formatRange, getElementWithPayload, getPayload, ghostEvent, hasPayload, hasYScroll, height, helperEvent, intl, intlRange, isObject, max, min, nextClosestDay, noTimePart, outsideEvent, prepareEventChunks, prevClosestDay, previewEvent, rect, repositionEvent, setContent, setMidnight, setPayload, sortEventChunks, subtractDay, subtractDuration, symbol, toEventWithLocalDates, toISOString, toLocalDate, toViewWithLocalDates, writable2 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@event-calendar/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"title": "Event Calendar Core package",
|
|
5
5
|
"description": "Full-sized drag & drop event calendar with resource view",
|
|
6
6
|
"keywords": [
|
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
"./package.json": "./package.json"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"
|
|
31
|
-
"svelte": "^3.55.1"
|
|
30
|
+
"svelte": "^3.59.1"
|
|
32
31
|
}
|
|
33
32
|
}
|