@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.
Files changed (79) hide show
  1. package/README.md +15 -4
  2. package/dist/index.css +2 -2
  3. package/dist/index.js +2201 -2128
  4. package/package.json +2 -2
  5. package/src/Buttons.svelte +36 -37
  6. package/src/Calendar.svelte +34 -37
  7. package/src/Toolbar.svelte +4 -4
  8. package/src/lib/components/BaseDay.svelte +13 -10
  9. package/src/lib/components/BaseEvent.svelte +17 -17
  10. package/src/lib/components/ColHead.svelte +6 -6
  11. package/src/lib/components/DayHeader.svelte +3 -3
  12. package/src/lib/components/InteractableEvent.svelte +7 -8
  13. package/src/lib/derived.js +80 -0
  14. package/src/lib/index.js +1 -2
  15. package/src/lib/slots.js +16 -16
  16. package/src/lib/utils.js +4 -9
  17. package/src/lib/view.js +0 -8
  18. package/src/plugins/day-grid/Day.svelte +25 -23
  19. package/src/plugins/day-grid/Event.svelte +15 -13
  20. package/src/plugins/day-grid/Popup.svelte +12 -12
  21. package/src/plugins/day-grid/View.svelte +24 -36
  22. package/src/plugins/day-grid/derived.js +102 -0
  23. package/src/plugins/day-grid/index.js +47 -36
  24. package/src/plugins/day-grid/state.svelte.js +19 -0
  25. package/src/plugins/interaction/Action.svelte +108 -76
  26. package/src/plugins/interaction/Auxiliary.svelte +9 -38
  27. package/src/plugins/interaction/Pointer.svelte +12 -17
  28. package/src/plugins/interaction/Resizer.svelte +9 -7
  29. package/src/plugins/interaction/effects.js +37 -0
  30. package/src/plugins/interaction/index.js +44 -38
  31. package/src/plugins/interaction/lib/utils.js +1 -1
  32. package/src/plugins/interaction/state.svelte.js +12 -0
  33. package/src/plugins/list/Day.svelte +8 -7
  34. package/src/plugins/list/Event.svelte +3 -3
  35. package/src/plugins/list/View.svelte +18 -13
  36. package/src/plugins/list/index.js +51 -43
  37. package/src/plugins/list/state.svelte.js +8 -0
  38. package/src/plugins/resource-time-grid/Label.svelte +8 -8
  39. package/src/plugins/resource-time-grid/View.svelte +38 -17
  40. package/src/plugins/resource-time-grid/derived.js +67 -0
  41. package/src/plugins/resource-time-grid/index.js +34 -28
  42. package/src/plugins/resource-time-grid/state.svelte.js +21 -0
  43. package/src/plugins/resource-timeline/Day.svelte +9 -4
  44. package/src/plugins/resource-timeline/Event.svelte +7 -6
  45. package/src/plugins/resource-timeline/Expander.svelte +7 -6
  46. package/src/plugins/resource-timeline/NowIndicator.svelte +10 -11
  47. package/src/plugins/resource-timeline/View.svelte +45 -63
  48. package/src/plugins/resource-timeline/derived.js +167 -0
  49. package/src/plugins/resource-timeline/index.js +17 -21
  50. package/src/plugins/resource-timeline/lib.js +4 -65
  51. package/src/plugins/resource-timeline/state.svelte.js +18 -0
  52. package/src/plugins/time-grid/Day.svelte +7 -2
  53. package/src/plugins/time-grid/Event.svelte +6 -6
  54. package/src/plugins/time-grid/NowIndicator.svelte +10 -9
  55. package/src/plugins/time-grid/View.svelte +46 -59
  56. package/src/plugins/time-grid/derived.js +162 -0
  57. package/src/plugins/time-grid/index.js +31 -25
  58. package/src/plugins/time-grid/lib.js +18 -74
  59. package/src/plugins/time-grid/options.js +21 -16
  60. package/src/plugins/time-grid/state.svelte.js +44 -0
  61. package/src/storage/derived.js +144 -0
  62. package/src/storage/effects.js +156 -0
  63. package/src/storage/options.svelte.js +275 -0
  64. package/src/storage/state.svelte.js +69 -0
  65. package/src/styles/events.css +1 -1
  66. package/src/Auxiliary.svelte +0 -47
  67. package/src/lib/debounce.js +0 -20
  68. package/src/lib/stores.js +0 -63
  69. package/src/plugins/day-grid/lib.js +0 -61
  70. package/src/plugins/day-grid/stores.js +0 -5
  71. package/src/plugins/resource-time-grid/lib.js +0 -31
  72. package/src/plugins/resource-time-grid/stores.js +0 -34
  73. package/src/plugins/resource-timeline/Header.svelte +0 -44
  74. package/src/plugins/resource-timeline/Label.svelte +0 -38
  75. package/src/plugins/resource-timeline/stores.js +0 -48
  76. package/src/plugins/time-grid/stores.js +0 -49
  77. package/src/storage/options.js +0 -136
  78. package/src/storage/state.js +0 -168
  79. package/src/storage/stores.js +0 -234
@@ -1,8 +1,7 @@
1
- import {btnTextDay, btnTextWeek, themeView} from '#lib';
1
+ import {assign, btnTextDay, btnTextWeek, themeView} from '#lib';
2
+ import {setExtensions} from '../time-grid/lib.js';
2
3
  import {createTROptions, createTRROptions, createTRRParsers} from '../time-grid/options.js';
3
- import {createTRRStores, createTRStores} from '../time-grid/stores.js';
4
4
  import {createRROptions} from './options.js';
5
- import {createRRStores} from './stores.js';
6
5
  import View from './View.svelte';
7
6
 
8
7
  export default {
@@ -10,34 +9,41 @@ export default {
10
9
  createTROptions(options);
11
10
  createTRROptions(options);
12
11
  createRROptions(options);
13
- options.datesAboveResources = false;
14
- // Common options
15
- options.buttonText.resourceTimeGridDay = 'resources';
16
- options.buttonText.resourceTimeGridWeek = 'resources';
17
- options.theme.colGroup = 'ec-col-group';
18
- options.view = 'resourceTimeGridWeek';
19
- options.views.resourceTimeGridDay = {
20
- buttonText: btnTextDay,
21
- component: View,
22
- dayHeaderFormat: {weekday: 'long'},
23
- duration: {days: 1},
24
- theme: themeView('ec-resource ec-time-grid ec-day-view')
25
- };
26
- options.views.resourceTimeGridWeek = {
27
- buttonText: btnTextWeek,
28
- component: View,
29
- duration: {weeks: 1},
30
- theme: themeView('ec-resource ec-time-grid ec-week-view')
31
- };
12
+ assign(options, {
13
+ datesAboveResources: false,
14
+ // Common options
15
+ view: 'resourceTimeGridWeek'
16
+ });
17
+ assign(options.buttonText, {
18
+ resourceTimeGridDay: 'resources',
19
+ resourceTimeGridWeek: 'resources'
20
+ });
21
+ assign(options.theme, {
22
+ colGroup: 'ec-col-group'
23
+ });
24
+ assign(options.views, {
25
+ resourceTimeGridDay: {
26
+ buttonText: btnTextDay,
27
+ component: initViewComponent,
28
+ dayHeaderFormat: {weekday: 'long'},
29
+ duration: {days: 1},
30
+ theme: themeView('ec-resource ec-time-grid ec-day-view')
31
+ },
32
+ resourceTimeGridWeek: {
33
+ buttonText: btnTextWeek,
34
+ component: initViewComponent,
35
+ duration: {weeks: 1},
36
+ theme: themeView('ec-resource ec-time-grid ec-week-view')
37
+ }
38
+ });
32
39
  },
33
40
 
34
41
  createParsers(parsers) {
35
42
  createTRRParsers(parsers);
36
- },
37
-
38
- createStores(state) {
39
- createTRRStores(state);
40
- createTRStores(state);
41
- createRRStores(state);
42
43
  }
43
44
  }
45
+
46
+ function initViewComponent(mainState) {
47
+ setExtensions(mainState);
48
+ return View;
49
+ }
@@ -0,0 +1,21 @@
1
+ import {TRRState, TRState} from '../time-grid/state.svelte.js';
2
+ import {grid, viewResources} from './derived.js';
3
+
4
+ /**
5
+ * ResourceTimeGrid + ResourceTimeline
6
+ */
7
+ export function RRState(Base){
8
+ return class extends Base {
9
+ constructor(mainState) {
10
+ super(mainState);
11
+ this.viewResources = $derived.by(viewResources(mainState));
12
+ }
13
+ }
14
+ }
15
+
16
+ export default class ViewState extends RRState(TRState(TRRState())) {
17
+ constructor(mainState) {
18
+ super(mainState);
19
+ this.grid = $derived.by(grid(mainState, this));
20
+ }
21
+ }
@@ -5,21 +5,26 @@
5
5
 
6
6
  let {day, noIeb, noBeb} = $props();
7
7
 
8
- let {_monthView, slotDuration, slotWidth} = getContext('state');
8
+ let {options: {slotWidth}} = $derived(getContext('state'));
9
+ let {monthView, snap} = $derived(getContext('view-state'));
9
10
 
10
11
  let {dayStart: date, start, resource, disabled, highlight} = $derived(day);
11
12
 
12
13
  let el = $state();
13
14
 
14
15
  function dateFromPoint(x, y) {
15
- if ($_monthView) {
16
+ if (monthView) {
16
17
  return date;
17
18
  } else {
18
19
  let dayRect = rect(el);
19
20
  let scaleX = dayRect.width / el.offsetWidth;
20
- return addDuration(cloneDate(start), $slotDuration, floor((isRtl() ? dayRect.right - x : x - dayRect.left) / ($slotWidth * scaleX)));
21
+ return addDuration(
22
+ cloneDate(start),
23
+ snap.duration,
24
+ floor((isRtl() ? dayRect.right - x : x - dayRect.left) / (slotWidth * snap.ratio * scaleX))
25
+ );
21
26
  }
22
27
  }
23
28
  </script>
24
29
 
25
- <BaseDay bind:el allDay={$_monthView} {date} {resource} {dateFromPoint} {disabled} {highlight} {noIeb} {noBeb}/>
30
+ <BaseDay bind:el allDay={monthView} {date} {resource} {dateFromPoint} {disabled} {highlight} {noIeb} {noBeb}/>
@@ -1,12 +1,13 @@
1
1
  <script>
2
2
  import {getContext} from 'svelte';
3
- import {height, helperEvent, toSeconds} from '#lib';
3
+ import {height, toSeconds} from '#lib';
4
4
  import {repositionEvent} from './lib.js';
5
5
  import {InteractableEvent} from '#components';
6
6
 
7
7
  let {chunk} = $props();
8
8
 
9
- let {slotDuration, slotWidth, _monthView} = getContext('state');
9
+ let {options: {slotDuration, slotWidth}} = $derived(getContext('state'));
10
+ let {monthView} = $derived(getContext('view-state'));
10
11
 
11
12
  let el = $state();
12
13
  let margin = $state(0);
@@ -15,10 +16,10 @@
15
16
  let styles = $derived(style => {
16
17
  style['grid-column'] = `${chunk.gridColumn} / span ${chunk.dates.length}`;
17
18
  style['grid-row'] = chunk.gridRow;
18
- if (!$_monthView) {
19
- let left = chunk.left / toSeconds($slotDuration) * $slotWidth;
19
+ if (!monthView) {
20
+ let left = chunk.left / toSeconds(slotDuration) * slotWidth;
20
21
  style['inset-inline-start'] = `${left}px`;
21
- style['inline-size'] = `${chunk.width / toSeconds($slotDuration) * $slotWidth}px`;
22
+ style['inline-size'] = `${chunk.width / toSeconds(slotDuration) * slotWidth}px`;
22
23
  }
23
24
  let marginTop = margin;
24
25
  if (event._margin) {
@@ -33,7 +34,7 @@
33
34
  });
34
35
 
35
36
  export function reposition() {
36
- margin = repositionEvent(chunk, height(el), $_monthView);
37
+ margin = repositionEvent(chunk, height(el), monthView);
37
38
  }
38
39
  </script>
39
40
 
@@ -1,10 +1,11 @@
1
1
  <script>
2
2
  import {getContext} from 'svelte';
3
- import {getPayload, identity} from '#lib';
3
+ import {getPayload} from '#lib';
4
4
 
5
5
  let {resource} = $props();
6
6
 
7
- let {resources, theme} = getContext('state');
7
+ let {options} = $derived(getContext('state'));
8
+ let {resources, theme} = $derived(options);
8
9
 
9
10
  let payload = $state.raw({});
10
11
  let expanded = $state(true);
@@ -18,7 +19,7 @@
18
19
  expanded = !expanded;
19
20
  payload.expanded = expanded;
20
21
  toggle(payload.children, expanded);
21
- resources.update(identity);
22
+ options.resources = [...resources];
22
23
  }
23
24
 
24
25
  function toggle(children, expand) {
@@ -33,12 +34,12 @@
33
34
  </script>
34
35
 
35
36
  {#each Array(payload.level) as level}
36
- <span class="{$theme.expander}"></span>
37
+ <span class="{theme.expander}"></span>
37
38
  {/each}
38
39
 
39
- <span class="{$theme.expander}">
40
+ <span class="{theme.expander}">
40
41
  {#if payload.children?.length}
41
- <button class="{$theme.button}" {onclick}>
42
+ <button class="{theme.button}" {onclick}>
42
43
  {#if expanded}&minus;{:else}&plus;{/if}
43
44
  </button>
44
45
  {/if}
@@ -2,41 +2,40 @@
2
2
  import {getContext} from 'svelte';
3
3
  import {datesEqual, toSeconds, intersectionObserver, isRtl} from '#lib';
4
4
 
5
- let {grid} = $props();
6
-
7
- let {_mainEl, _now, _today, _sidebarWidth, slotDuration, slotWidth, theme} = getContext('state');
5
+ let {mainEl, now, today, options: {slotDuration, slotWidth, theme}} = $derived(getContext('state'));
6
+ let {grid, sidebarWidth} = $derived(getContext('view-state'));
8
7
 
9
8
  // Layout
10
9
  let {gridColumn, start, end} = $derived.by(() => {
11
10
  for (let day of grid[0]) {
12
- if (datesEqual(day.dayStart, $_today)) {
11
+ if (datesEqual(day.dayStart, today)) {
13
12
  return day;
14
13
  }
15
14
  }
16
15
  return {};
17
16
  });
18
17
  let left = $derived.by(() => {
19
- if ($_now < start || $_now > end) {
18
+ if (now < start || now > end) {
20
19
  return null;
21
20
  }
22
- let step = toSeconds($slotDuration);
23
- return ($_now - start) / 1000 / step * $slotWidth;
21
+ let step = toSeconds(slotDuration);
22
+ return (now - start) / 1000 / step * slotWidth;
24
23
  });
25
24
 
26
25
  // Observe intersections
27
26
  let observerOptions = $derived({
28
- root: $_mainEl,
29
- rootMargin: isRtl() ? `0px -${$_sidebarWidth + 1}px 0px 0px` : `0px 0px 0px -${$_sidebarWidth + 1}px`,
27
+ root: mainEl,
28
+ rootMargin: isRtl() ? `0px -${sidebarWidth + 1}px 0px 0px` : `0px 0px 0px -${sidebarWidth + 1}px`,
30
29
  threshold: 0.0,
31
30
  });
32
31
  function onIntersect(el, entry) {
33
- el.classList.toggle($theme.hidden, !entry.isIntersecting);
32
+ el.classList.toggle(theme.hidden, !entry.isIntersecting);
34
33
  }
35
34
  </script>
36
35
 
37
36
  {#if gridColumn && left !== null}
38
37
  <div {@attach intersectionObserver(onIntersect, observerOptions)}
39
- class="{$theme.nowIndicator}"
38
+ class="{theme.nowIndicator}"
40
39
  style:grid-column="{gridColumn + 1}"
41
40
  style:grid-row="2 / span {grid.length}"
42
41
  style:inset-inline-start="{left}px"
@@ -1,60 +1,42 @@
1
1
  <script>
2
- import {getContext, tick} from 'svelte';
3
- import {
4
- max, resizeObserver, runReposition, contentFrom, toSeconds, datesEqual, min, isRtl, DAY_IN_SECONDS, addDuration,
5
- subtractDay, cloneDate, identity
6
- } from "#lib";
7
- import {createGrid, createEventChunks, createIEventChunks, getSlotTimeLimits} from './lib.js';
2
+ import {getContext, setContext, tick} from 'svelte';
3
+ import {max, resizeObserver, runReposition, contentFrom, toSeconds, datesEqual, min, isRtl} from '#lib';
4
+ import {getSlotTimeLimits} from './lib.js';
5
+ import ViewState from './state.svelte.js';
8
6
  import {ColHead, DayHeader} from '#components';
7
+ import Label from '../resource-time-grid/Label.svelte';
9
8
  import Day from './Day.svelte';
10
9
  import Event from './Event.svelte';
11
- import Label from './Label.svelte';
12
10
  import Expander from './Expander.svelte';
13
11
  import NowIndicator from './NowIndicator.svelte';
14
12
 
15
- let {_activeRangeExt, _daySlots, _dayTimeLimits, _filteredEvents, _iEvents, _mainEl, _monthView, _nestedResources, _sidebarWidth,
16
- _slotLabelPeriodicity, _today, _viewResources, _viewDates, columnWidth, highlightedDates, nowIndicator, scrollTime,
17
- slotDuration, slotHeight, slotMaxTime, slotWidth, theme, validRange} = getContext('state');
13
+ let mainState = getContext('state');
14
+ let viewState = new ViewState(mainState);
15
+ setContext('view-state', viewState);
18
16
 
19
- let headerHeight = $state(0);
20
-
21
- let grid = $derived(createGrid($_viewDates, $_viewResources, $_dayTimeLimits, $validRange, $highlightedDates));
22
- let {chunks, bgChunks} = $derived(createEventChunks($_filteredEvents, grid));
23
- let iChunks = $derived(createIEventChunks($_iEvents, grid));
17
+ let {mainEl, today, viewDates, options: {columnWidth, nowIndicator, scrollTime, slotDuration, slotHeight, slotWidth, theme}} = $derived(mainState);
18
+ let {chunks, bgChunks, iChunks, daySlots, dayTimeLimits, grid, monthView, nestedResources, sidebarWidth,
19
+ slotLabelPeriodicity, viewResources} = $derived(viewState);
24
20
 
25
- $effect.pre(() => {
26
- $_activeRangeExt = ({start, end}) => {
27
- if ($slotMaxTime.days || $slotMaxTime.seconds > DAY_IN_SECONDS) {
28
- addDuration(subtractDay(end), $slotMaxTime);
29
- let start2 = subtractDay(cloneDate(end));
30
- if (start2 < start) {
31
- start = start2;
32
- }
33
- }
34
- return {start, end};
35
- };
36
- return () => {
37
- $_activeRangeExt = identity;
38
- };
39
- });
21
+ let headerHeight = $state(0);
40
22
 
41
23
  // Handle scrollTime
42
24
  $effect(() => {
43
- $_viewDates;
44
- $scrollTime;
25
+ viewDates;
26
+ scrollTime;
45
27
  tick().then(scrollToTime);
46
28
  });
47
29
  function scrollToTime() {
48
- if ($_monthView) {
30
+ if (monthView) {
49
31
  return;
50
32
  }
51
33
  let scrollLeft = 0;
52
- let todayOutOfView = $_today < $_viewDates[0] || $_today > $_viewDates.at(-1);
53
- for (let date of $_viewDates) {
54
- let slotTimeLimits = getSlotTimeLimits($_dayTimeLimits, date);
55
- if (todayOutOfView || datesEqual(date, $_today)) {
34
+ let todayOutOfView = today < viewDates[0] || today > viewDates.at(-1);
35
+ for (let date of viewDates) {
36
+ let slotTimeLimits = getSlotTimeLimits(dayTimeLimits, date);
37
+ if (todayOutOfView || datesEqual(date, today)) {
56
38
  scrollLeft += max(
57
- min(toSeconds($scrollTime), toSeconds(slotTimeLimits.max)) - toSeconds(slotTimeLimits.min),
39
+ min(toSeconds(scrollTime), toSeconds(slotTimeLimits.max)) - toSeconds(slotTimeLimits.min),
58
40
  0
59
41
  );
60
42
  break;
@@ -62,7 +44,7 @@
62
44
  scrollLeft += toSeconds(slotTimeLimits.max) - toSeconds(slotTimeLimits.min);
63
45
  }
64
46
  }
65
- $_mainEl.scrollLeft = scrollLeft / toSeconds($slotDuration) * $slotWidth * (isRtl() ? -1 : 1);
47
+ mainEl.scrollLeft = scrollLeft / toSeconds(slotDuration) * slotWidth * (isRtl() ? -1 : 1);
66
48
  }
67
49
 
68
50
  // Events reposition
@@ -74,32 +56,32 @@
74
56
  </script>
75
57
 
76
58
  <section
77
- bind:this={$_mainEl}
78
- class="{$theme.main}"
59
+ bind:this={mainState.mainEl}
60
+ class="{theme.main}"
79
61
  style:--ec-grid-cols="{grid[0].length}"
80
- style:--ec-grid-rows="{grid.length > 1 ? `repeat(${grid.length - 1}, auto)` : ''} minmax(auto, 1fr)"
81
- style:--ec-col-width="{$columnWidth ?? 'minmax(4em, 1fr)'}"
82
- style:--ec-slot-label-periodicity="{$_slotLabelPeriodicity}"
83
- style:--ec-slot-height="{$slotHeight}px"
84
- style:--ec-slot-width="{$slotWidth}px"
62
+ style:--ec-grid-rows="{grid.length > 1 ? `repeat(${grid.length - 1}, auto)` : ''} 1fr"
63
+ style:--ec-col-width="{columnWidth ?? 'minmax(4em, 1fr)'}"
64
+ style:--ec-slot-label-periodicity="{slotLabelPeriodicity}"
65
+ style:--ec-slot-height="{slotHeight}px"
66
+ style:--ec-slot-width="{slotWidth}px"
85
67
  style:--ec-header-height="{headerHeight}px"
86
- style:--ec-sidebar-width="{$_sidebarWidth}px"
68
+ style:--ec-sidebar-width="{sidebarWidth}px"
87
69
  {@attach resizeObserver(reposition)}
88
70
  >
89
- <header bind:offsetHeight={headerHeight} class="{$theme.header}">
90
- <aside class="{$theme.sidebar}" bind:offsetWidth={$_sidebarWidth}></aside>
91
- <div class="{$theme.grid}" role="row">
71
+ <header bind:offsetHeight={headerHeight} class="{theme.header}">
72
+ <aside class="{theme.sidebar}" bind:offsetWidth={viewState.sidebarWidth}></aside>
73
+ <div class="{theme.grid}" role="row">
92
74
  {#each grid[0] as {dayStart: date, disabled, highlight}, i}
93
75
  <ColHead {date} colIndex={1 + i} {disabled} {highlight}>
94
76
  <DayHeader {date}/>
95
77
  </ColHead>
96
78
  {/each}
97
- {#if !$_monthView}
79
+ {#if !monthView}
98
80
  {#each grid[0] as {dayStart: date, disabled, highlight}}
99
- <ColHead {date} className={$theme.slots} {disabled} {highlight} ariaHidden>
100
- {#each $_daySlots[date.getTime()] as slot}
81
+ <ColHead {date} className={theme.slots} {disabled} {highlight} ariaHidden>
82
+ {#each daySlots[date.getTime()] as slot}
101
83
  <div
102
- class="{$theme.slot}"
84
+ class="{theme.slot}"
103
85
  style:--ec-slot-label-periodicity={slot[2]}
104
86
  >
105
87
  <time
@@ -114,25 +96,25 @@
114
96
  </div>
115
97
  </header>
116
98
 
117
- <div class="{$theme.body}" role="rowgroup">
118
- <aside class="{$theme.sidebar}">
119
- {#each $_viewResources as resource}
120
- <div class="{$theme.rowHead}" role="rowheader">
121
- {#if $_nestedResources}
99
+ <div class="{theme.body}" role="rowgroup">
100
+ <aside class="{theme.sidebar}">
101
+ {#each viewResources as resource}
102
+ <div class="{theme.rowHead}" role="rowheader">
103
+ {#if nestedResources}
122
104
  <Expander {resource} />
123
105
  {/if}
124
106
  <Label {resource}/>
125
107
  </div>
126
108
  {/each}
127
109
  </aside>
128
- <div class="{$theme.grid}" role="row">
110
+ <div class="{theme.grid}" role="row">
129
111
  {#each grid as days, i}
130
112
  {#each days as day, j}
131
113
  <Day {day} noIeb={j + 1 === days.length} noBeb={i + 1 === grid.length}/>
132
114
  {/each}
133
115
  {/each}
134
116
  </div>
135
- <div class="{$theme.events}">
117
+ <div class="{theme.events}">
136
118
  {#each chunks as chunk, i}
137
119
  <!-- svelte-ignore binding_property_non_reactive -->
138
120
  <Event bind:this={refs[i]} {chunk}/>
@@ -146,7 +128,7 @@
146
128
  </div>
147
129
  </div>
148
130
 
149
- {#if $nowIndicator && !$_monthView}
150
- <NowIndicator {grid} />
131
+ {#if nowIndicator && !monthView}
132
+ <NowIndicator/>
151
133
  {/if}
152
134
  </section>
@@ -0,0 +1,167 @@
1
+ import {untrack} from 'svelte';
2
+ import {
3
+ addDay, addDuration, bgEvent, cloneDate, createSlots, createSlotTimeLimits, datesEqual, getPayload, outsideRange,
4
+ toSeconds
5
+ } from '#lib';
6
+ import {createChunks, prepareChunks} from './lib.js';
7
+
8
+ export function grid(mainState, viewState) {
9
+ return () => {
10
+ // Dependencies
11
+ let {viewDates, options: {highlightedDates, validRange}} = mainState;
12
+ let {dayTimeLimits, viewResources} = viewState;
13
+
14
+ let grid = [];
15
+
16
+ untrack(() => {
17
+ let gridRow = 1
18
+ for (let resource of viewResources) {
19
+ let days = [];
20
+ let gridColumn = 1;
21
+ for (let date of viewDates) {
22
+ let slotTimeLimits = dayTimeLimits[date.getTime()];
23
+ days.push({
24
+ gridColumn,
25
+ gridRow,
26
+ resource,
27
+ start: addDuration(cloneDate(date), slotTimeLimits.min),
28
+ end: addDuration(cloneDate(date), slotTimeLimits.max),
29
+ dayStart: date,
30
+ dayEnd: addDay(cloneDate(date)),
31
+ disabled: outsideRange(date, validRange),
32
+ highlight: highlightedDates.some(d => datesEqual(d, date))
33
+ });
34
+ ++gridColumn;
35
+ }
36
+ grid.push(days);
37
+ ++gridRow;
38
+ }
39
+ });
40
+
41
+ return grid;
42
+ };
43
+ }
44
+
45
+ export function eventChunks(mainState, viewState) {
46
+ return () => {
47
+ // Dependencies
48
+ let {filteredEvents} = mainState;
49
+ let {grid} = viewState;
50
+
51
+ let chunks = [];
52
+ let bgChunks = [];
53
+
54
+ untrack(() => {
55
+ for (let event of filteredEvents) {
56
+ for (let days of grid) {
57
+ if (bgEvent(event.display)) {
58
+ bgChunks = bgChunks.concat(createChunks(event, days));
59
+ } else {
60
+ chunks = chunks.concat(createChunks(event, days));
61
+ }
62
+ }
63
+ }
64
+ prepareChunks(chunks);
65
+ });
66
+
67
+ return {chunks, bgChunks};
68
+ };
69
+ }
70
+
71
+ export function iEventChunks(mainState, viewState) {
72
+ return () => {
73
+ // Dependencies
74
+ let {iEvents} = mainState;
75
+ let {grid} = viewState;
76
+
77
+ let iChunks = [];
78
+
79
+ for (let [, event] of iEvents) {
80
+ if (!event) {
81
+ continue;
82
+ }
83
+ untrack(() => {
84
+ for (let days of grid) {
85
+ iChunks = iChunks.concat(createChunks(event, days));
86
+ }
87
+ });
88
+ }
89
+
90
+ return iChunks;
91
+ };
92
+ }
93
+
94
+ // slotTimeLimits per day
95
+ export function dayTimeLimits(mainState) {
96
+ return () => {
97
+ // Dependencies
98
+ let {filteredEvents, viewDates, options: {flexibleSlotTimeLimits, slotMinTime, slotMaxTime}} = mainState;
99
+
100
+ let dayTimeLimits = {};
101
+
102
+ untrack(() => {
103
+ for (let date of viewDates) {
104
+ dayTimeLimits[date.getTime()] = createSlotTimeLimits(
105
+ slotMinTime,
106
+ slotMaxTime,
107
+ flexibleSlotTimeLimits,
108
+ [date],
109
+ filteredEvents
110
+ );
111
+ }
112
+ });
113
+
114
+ return dayTimeLimits;
115
+ };
116
+ }
117
+
118
+ export function daySlots(mainState, viewState) {
119
+ return () => {
120
+ // Dependencies
121
+ let {viewDates, options: {slotDuration}} = mainState;
122
+ let {dayTimeLimits, intlSlotLabel, slotLabelPeriodicity} = viewState;
123
+
124
+ let slots = {};
125
+
126
+ untrack(() => {
127
+ for (let date of viewDates) {
128
+ let key = date.getTime();
129
+ slots[key] = key in dayTimeLimits
130
+ ? createSlots(date, slotDuration, slotLabelPeriodicity, dayTimeLimits[key], intlSlotLabel)
131
+ : [];
132
+ }
133
+ });
134
+
135
+ return slots;
136
+ };
137
+ }
138
+
139
+ export function nestedResources(mainState) {
140
+ return () => {
141
+ // Dependencies
142
+ let {options: {resources}} = mainState;
143
+
144
+ let nested;
145
+
146
+ untrack(() => {
147
+ nested = resources.some(resource => getPayload(resource).children.length);
148
+ });
149
+
150
+ return nested;
151
+ };
152
+ }
153
+
154
+ export function monthView(mainState) {
155
+ return () => {
156
+ // Dependencies
157
+ let {options: {slotDuration}} = mainState;
158
+
159
+ let monthView;
160
+
161
+ untrack(() => {
162
+ monthView = !toSeconds(slotDuration);
163
+ });
164
+
165
+ return monthView;
166
+ };
167
+ }