@dayflow/svelte 3.0.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/dist/index.js +218 -0
- package/dist/index.js.map +1 -0
- package/dist/index.ssr.js +114 -0
- package/dist/index.ssr.js.map +1 -0
- package/index.d.ts +40 -0
- package/package.json +53 -0
- package/src/DayFlowCalendar.svelte +110 -0
- package/src/index.ts +18 -0
- package/src/svelte-shims.d.ts +5 -0
- package/src/useCalendarApp.ts +78 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import 'svelte/internal/disclose-version';
|
|
2
|
+
import * as $ from 'svelte/internal/client';
|
|
3
|
+
import { onMount, tick, onDestroy } from 'svelte';
|
|
4
|
+
import { CalendarApp } from '@dayflow/core';
|
|
5
|
+
export * from '@dayflow/core';
|
|
6
|
+
export { CalendarApp, CalendarRegistry, ViewType, createDayView, createDragPlugin, createEventsPlugin, createMonthView, createWeekView, createYearView } from '@dayflow/core';
|
|
7
|
+
import { writable } from 'svelte/store';
|
|
8
|
+
|
|
9
|
+
var root_4 = $.from_html(`<div><!></div>`);
|
|
10
|
+
var root_1 = $.from_html(`<div class="df-calendar-wrapper"></div> <!>`, 1);
|
|
11
|
+
var root_5 = $.from_html(`<div class="df-calendar-wrapper df-calendar-ssr-placeholder"></div>`);
|
|
12
|
+
|
|
13
|
+
function DayFlowCalendar($$anchor, $$props) {
|
|
14
|
+
$.push($$props, true);
|
|
15
|
+
|
|
16
|
+
let eventContent = $.prop($$props, 'eventContent', 3, null),
|
|
17
|
+
eventDetailContent = $.prop($$props, 'eventDetailContent', 3, null),
|
|
18
|
+
eventDetailDialog = $.prop($$props, 'eventDetailDialog', 3, null),
|
|
19
|
+
headerContent = $.prop($$props, 'headerContent', 3, null),
|
|
20
|
+
createCalendarDialog = $.prop($$props, 'createCalendarDialog', 3, null),
|
|
21
|
+
titleBarSlot = $.prop($$props, 'titleBarSlot', 3, null),
|
|
22
|
+
colorPicker = $.prop($$props, 'colorPicker', 3, null),
|
|
23
|
+
colorPickerWrapper = $.prop($$props, 'colorPickerWrapper', 3, null);
|
|
24
|
+
|
|
25
|
+
let container = $.state(void 0);
|
|
26
|
+
let renderer;
|
|
27
|
+
let customRenderings = $.state($.proxy([]));
|
|
28
|
+
let unsubscribe;
|
|
29
|
+
let mounted = $.state(false);
|
|
30
|
+
|
|
31
|
+
// Guard for browser environment
|
|
32
|
+
const isBrowser = typeof window !== 'undefined';
|
|
33
|
+
|
|
34
|
+
const app = $.derived(() => $$props.calendar.app || $$props.calendar);
|
|
35
|
+
|
|
36
|
+
const renderProps = $.derived(() => ({
|
|
37
|
+
eventContent: eventContent(),
|
|
38
|
+
eventDetailContent: eventDetailContent(),
|
|
39
|
+
eventDetailDialog: eventDetailDialog(),
|
|
40
|
+
headerContent: headerContent(),
|
|
41
|
+
createCalendarDialog: createCalendarDialog(),
|
|
42
|
+
titleBarSlot: titleBarSlot(),
|
|
43
|
+
colorPicker: colorPicker(),
|
|
44
|
+
colorPickerWrapper: colorPickerWrapper()
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
onMount(async () => {
|
|
48
|
+
if (!$.get(container)) return;
|
|
49
|
+
|
|
50
|
+
await tick();
|
|
51
|
+
|
|
52
|
+
const { CalendarRenderer } = await import('@dayflow/core');
|
|
53
|
+
|
|
54
|
+
renderer = new CalendarRenderer($.get(app));
|
|
55
|
+
renderer.mount($.get(container));
|
|
56
|
+
|
|
57
|
+
unsubscribe = renderer.getCustomRenderingStore().subscribe((renderings) => {
|
|
58
|
+
$.set(customRenderings, Array.from(renderings.values()), true);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const activeOverrides = Object.keys($.get(renderProps)).filter((key) => $.get(renderProps)[key] !== null);
|
|
62
|
+
|
|
63
|
+
renderer.getCustomRenderingStore().setOverrides(activeOverrides);
|
|
64
|
+
$.set(mounted, true);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
onDestroy(() => {
|
|
68
|
+
if (unsubscribe) unsubscribe();
|
|
69
|
+
if (renderer) renderer.unmount();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
function portal(node, target) {
|
|
73
|
+
if (!target || !node || !isBrowser) return;
|
|
74
|
+
|
|
75
|
+
target.appendChild(node);
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
destroy() {
|
|
79
|
+
if (node.parentNode === target) {
|
|
80
|
+
target.removeChild(node);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
var fragment = $.comment();
|
|
87
|
+
var node_1 = $.first_child(fragment);
|
|
88
|
+
|
|
89
|
+
{
|
|
90
|
+
var consequent_2 = ($$anchor) => {
|
|
91
|
+
var fragment_1 = root_1();
|
|
92
|
+
var div = $.first_child(fragment_1);
|
|
93
|
+
|
|
94
|
+
$.bind_this(div, ($$value) => $.set(container, $$value), () => $.get(container));
|
|
95
|
+
|
|
96
|
+
var node_2 = $.sibling(div, 2);
|
|
97
|
+
|
|
98
|
+
{
|
|
99
|
+
var consequent_1 = ($$anchor) => {
|
|
100
|
+
var fragment_2 = $.comment();
|
|
101
|
+
var node_3 = $.first_child(fragment_2);
|
|
102
|
+
|
|
103
|
+
$.each(node_3, 17, () => $.get(customRenderings), (rendering) => rendering.id, ($$anchor, rendering) => {
|
|
104
|
+
const Component = $.derived(() => $.get(renderProps)[$.get(rendering).generatorName]);
|
|
105
|
+
var fragment_3 = $.comment();
|
|
106
|
+
var node_4 = $.first_child(fragment_3);
|
|
107
|
+
|
|
108
|
+
{
|
|
109
|
+
var consequent = ($$anchor) => {
|
|
110
|
+
var div_1 = root_4();
|
|
111
|
+
var node_5 = $.child(div_1);
|
|
112
|
+
|
|
113
|
+
$.component(node_5, () => $.get(Component), ($$anchor, Component_1) => {
|
|
114
|
+
Component_1($$anchor, $.spread_props(() => $.get(rendering).generatorArgs));
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
$.reset(div_1);
|
|
118
|
+
$.action(div_1, ($$node, $$action_arg) => portal?.($$node, $$action_arg), () => $.get(rendering).containerEl);
|
|
119
|
+
$.append($$anchor, div_1);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
$.if(node_4, ($$render) => {
|
|
123
|
+
if ($.get(Component) && $.get(rendering).containerEl) $$render(consequent);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
$.append($$anchor, fragment_3);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
$.append($$anchor, fragment_2);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
$.if(node_2, ($$render) => {
|
|
134
|
+
if ($.get(mounted)) $$render(consequent_1);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
$.append($$anchor, fragment_1);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
var alternate = ($$anchor) => {
|
|
142
|
+
var div_2 = root_5();
|
|
143
|
+
|
|
144
|
+
$.append($$anchor, div_2);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
$.if(node_1, ($$render) => {
|
|
148
|
+
if (isBrowser) $$render(consequent_2); else $$render(alternate, false);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
$.append($$anchor, fragment);
|
|
153
|
+
$.pop();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function useCalendarApp(config) {
|
|
157
|
+
const app = new CalendarApp(config);
|
|
158
|
+
const stateStore = writable({
|
|
159
|
+
currentView: app.state.currentView,
|
|
160
|
+
currentDate: app.state.currentDate,
|
|
161
|
+
events: app.getEvents()
|
|
162
|
+
});
|
|
163
|
+
app.subscribe((updatedApp) => {
|
|
164
|
+
stateStore.set({
|
|
165
|
+
currentView: updatedApp.state.currentView,
|
|
166
|
+
currentDate: updatedApp.state.currentDate,
|
|
167
|
+
events: updatedApp.getEvents()
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
const result = {
|
|
171
|
+
app,
|
|
172
|
+
get currentView() {
|
|
173
|
+
let val;
|
|
174
|
+
stateStore.subscribe((s) => val = s.currentView)();
|
|
175
|
+
return val;
|
|
176
|
+
},
|
|
177
|
+
get currentDate() {
|
|
178
|
+
let val;
|
|
179
|
+
stateStore.subscribe((s) => val = s.currentDate)();
|
|
180
|
+
return val;
|
|
181
|
+
},
|
|
182
|
+
get events() {
|
|
183
|
+
let val;
|
|
184
|
+
stateStore.subscribe((s) => val = s.events)();
|
|
185
|
+
return val;
|
|
186
|
+
},
|
|
187
|
+
applyEventsChanges: app.applyEventsChanges.bind(app),
|
|
188
|
+
changeView: app.changeView.bind(app),
|
|
189
|
+
setCurrentDate: app.setCurrentDate.bind(app),
|
|
190
|
+
addEvent: app.addEvent.bind(app),
|
|
191
|
+
updateEvent: app.updateEvent.bind(app),
|
|
192
|
+
deleteEvent: app.deleteEvent.bind(app),
|
|
193
|
+
undo: app.undo.bind(app),
|
|
194
|
+
goToToday: app.goToToday.bind(app),
|
|
195
|
+
goToPrevious: app.goToPrevious.bind(app),
|
|
196
|
+
goToNext: app.goToNext.bind(app),
|
|
197
|
+
selectDate: app.selectDate.bind(app),
|
|
198
|
+
getCalendars: app.getCalendars.bind(app),
|
|
199
|
+
createCalendar: app.createCalendar.bind(app),
|
|
200
|
+
mergeCalendars: app.mergeCalendars.bind(app),
|
|
201
|
+
setCalendarVisibility: app.setCalendarVisibility.bind(app),
|
|
202
|
+
setAllCalendarsVisibility: app.setAllCalendarsVisibility.bind(app),
|
|
203
|
+
getAllEvents: app.getAllEvents.bind(app),
|
|
204
|
+
highlightEvent: app.highlightEvent.bind(app),
|
|
205
|
+
setVisibleMonth: app.setVisibleMonth.bind(app),
|
|
206
|
+
getVisibleMonth: app.getVisibleMonth.bind(app),
|
|
207
|
+
get sidebarConfig() {
|
|
208
|
+
return app.getSidebarConfig();
|
|
209
|
+
},
|
|
210
|
+
get readOnlyConfig() {
|
|
211
|
+
return app.getReadOnlyConfig();
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export { DayFlowCalendar, DayFlowCalendar as default, useCalendarApp };
|
|
218
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/DayFlowCalendar.svelte","../src/useCalendarApp.ts"],"sourcesContent":["<script lang=\"ts\">\n import { onMount, onDestroy, tick } from 'svelte';\n import {\n CalendarRenderer,\n type ICalendarApp,\n type UseCalendarAppReturn,\n type CustomRendering,\n } from '@dayflow/core';\n\n let {\n calendar,\n eventContent = null,\n eventDetailContent = null,\n eventDetailDialog = null,\n headerContent = null,\n createCalendarDialog = null,\n titleBarSlot = null,\n colorPicker = null,\n colorPickerWrapper = null,\n } = $props<{\n calendar: ICalendarApp | UseCalendarAppReturn;\n eventContent?: any;\n eventDetailContent?: any;\n eventDetailDialog?: any;\n headerContent?: any;\n createCalendarDialog?: any;\n titleBarSlot?: any;\n colorPicker?: any;\n colorPickerWrapper?: any;\n }>();\n\n let container: HTMLElement | undefined = $state();\n let renderer: CalendarRenderer | undefined;\n let customRenderings: CustomRendering[] = $state([]);\n let unsubscribe: (() => void) | undefined;\n let mounted = $state(false);\n\n // Guard for browser environment\n const isBrowser = typeof window !== 'undefined';\n\n const app = $derived((calendar as any).app || calendar);\n\n const renderProps = $derived({\n eventContent,\n eventDetailContent,\n eventDetailDialog,\n headerContent,\n createCalendarDialog,\n titleBarSlot,\n colorPicker,\n colorPickerWrapper,\n } as Record<string, any>);\n\n onMount(async () => {\n if (!container) return;\n\n await tick();\n\n const { CalendarRenderer } = await import('@dayflow/core');\n\n renderer = new CalendarRenderer(app);\n renderer.mount(container);\n\n unsubscribe = renderer.getCustomRenderingStore().subscribe(renderings => {\n customRenderings = Array.from(renderings.values());\n });\n\n const activeOverrides = Object.keys(renderProps).filter(\n key => renderProps[key] !== null\n );\n renderer.getCustomRenderingStore().setOverrides(activeOverrides);\n\n mounted = true;\n });\n\n onDestroy(() => {\n if (unsubscribe) unsubscribe();\n if (renderer) renderer.unmount();\n });\n\n function portal(node: HTMLElement, target: HTMLElement) {\n if (!target || !node || !isBrowser) return;\n target.appendChild(node);\n return {\n destroy() {\n if (node.parentNode === target) {\n target.removeChild(node);\n }\n },\n };\n }\n</script>\n\n{#if isBrowser}\n <div bind:this={container} class=\"df-calendar-wrapper\"></div>\n\n {#if mounted}\n {#each customRenderings as rendering (rendering.id)}\n {@const Component = renderProps[rendering.generatorName]}\n {#if Component && rendering.containerEl}\n <div use:portal={rendering.containerEl}>\n <Component {...rendering.generatorArgs} />\n </div>\n {/if}\n {/each}\n {/if}\n{:else}\n <!-- SSR Placeholder -->\n <div class=\"df-calendar-wrapper df-calendar-ssr-placeholder\"></div>\n{/if}\n","import { writable } from 'svelte/store';\nimport type { Writable } from 'svelte/store';\nimport { CalendarApp } from '@dayflow/core';\nimport type {\n CalendarAppConfig,\n UseCalendarAppReturn,\n ICalendarApp,\n} from '@dayflow/core';\n\nexport function useCalendarApp(\n config: CalendarAppConfig\n): UseCalendarAppReturn {\n const app = new CalendarApp(config);\n\n // Create a store for the parts of state we want to be reactive in Svelte\n const stateStore = writable({\n currentView: app.state.currentView,\n currentDate: app.state.currentDate,\n events: app.getEvents(),\n });\n\n const unsubscribe = app.subscribe(updatedApp => {\n stateStore.set({\n currentView: updatedApp.state.currentView,\n currentDate: updatedApp.state.currentDate,\n events: updatedApp.getEvents(),\n });\n });\n\n // Proxy the state properties\n const result = {\n app,\n get currentView() {\n let val;\n stateStore.subscribe(s => (val = s.currentView))();\n return val;\n },\n get currentDate() {\n let val;\n stateStore.subscribe(s => (val = s.currentDate))();\n return val;\n },\n get events() {\n let val;\n stateStore.subscribe(s => (val = s.events))();\n return val;\n },\n\n applyEventsChanges: app.applyEventsChanges.bind(app),\n changeView: app.changeView.bind(app),\n setCurrentDate: app.setCurrentDate.bind(app),\n addEvent: app.addEvent.bind(app),\n updateEvent: app.updateEvent.bind(app),\n deleteEvent: app.deleteEvent.bind(app),\n undo: app.undo.bind(app),\n goToToday: app.goToToday.bind(app),\n goToPrevious: app.goToPrevious.bind(app),\n goToNext: app.goToNext.bind(app),\n selectDate: app.selectDate.bind(app),\n getCalendars: app.getCalendars.bind(app),\n createCalendar: app.createCalendar.bind(app),\n mergeCalendars: app.mergeCalendars.bind(app),\n setCalendarVisibility: app.setCalendarVisibility.bind(app),\n setAllCalendarsVisibility: app.setAllCalendarsVisibility.bind(app),\n getAllEvents: app.getAllEvents.bind(app),\n highlightEvent: app.highlightEvent.bind(app),\n setVisibleMonth: app.setVisibleMonth.bind(app),\n getVisibleMonth: app.getVisibleMonth.bind(app),\n get sidebarConfig() {\n return app.getSidebarConfig();\n },\n get readOnlyConfig() {\n return app.getReadOnlyConfig();\n },\n } as unknown as UseCalendarAppReturn;\n\n return result;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;4CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8FG,GAAG,GAAA,CAAA,CAAA,WAAA,CAAA,UAAA,CAAA;;eAAH,GAAG,EAAA,CAAA,OAAA,KAAA,CAAA,CAAA,GAAA,CAAY,SAAS,EAAA,OAAA,CAAA,EAAA,MAAA,CAAA,CAAA,GAAA,CAAT,SAAS,CAAA,CAAA;;0BAAxB,GAAG,EAAA,CAAA,CAAA;;;;;;;AAGK,KAAA,CAAA,CAAA,IAAA,CAAA,MAAA,EAAA,EAAA,EAAA,MAAA,CAAA,CAAA,GAAA,CAAA,gBAAgB,IAAI,SAAS,KAAE,SAAS,CAAC,EAAE,aAAvB,SAAS,KAAA;AAC1B,MAAA,MAAA,SAAS,GAAA,CAAA,CAAA,OAAA,CAAA,MAAA,CAAA,CAAA,GAAA,CAAG,WAAW,CAAA,CAAA,CAAA,CAAA,GAAA,CAAC,SAAS,EAAC,aAAa,C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
|
4
|
+
export * from '@dayflow/core';
|
|
5
|
+
export { CalendarApp, CalendarRegistry, ViewType, createDayView, createDragPlugin, createEventsPlugin, createMonthView, createWeekView, createYearView } from '@dayflow/core';
|
|
6
|
+
import { writable } from 'svelte/store';
|
|
7
|
+
|
|
8
|
+
function DayFlowCalendar($$renderer, $$props) {
|
|
9
|
+
$$renderer.component(($$renderer) => {
|
|
10
|
+
let {
|
|
11
|
+
calendar,
|
|
12
|
+
eventContent = null,
|
|
13
|
+
eventDetailContent = null,
|
|
14
|
+
eventDetailDialog = null,
|
|
15
|
+
headerContent = null,
|
|
16
|
+
createCalendarDialog = null,
|
|
17
|
+
titleBarSlot = null,
|
|
18
|
+
colorPicker = null,
|
|
19
|
+
colorPickerWrapper = null
|
|
20
|
+
} = $$props;
|
|
21
|
+
|
|
22
|
+
// Guard for browser environment
|
|
23
|
+
const isBrowser = typeof window !== 'undefined';
|
|
24
|
+
|
|
25
|
+
calendar.app || calendar;
|
|
26
|
+
|
|
27
|
+
onMount(async () => {
|
|
28
|
+
return;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
onDestroy(() => {
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (isBrowser) {
|
|
35
|
+
$$renderer.push('<!--[-->');
|
|
36
|
+
$$renderer.push(`<div class="df-calendar-wrapper"></div> `);
|
|
37
|
+
|
|
38
|
+
{
|
|
39
|
+
$$renderer.push('<!--[!-->');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
$$renderer.push(`<!--]-->`);
|
|
43
|
+
} else {
|
|
44
|
+
$$renderer.push('<!--[!-->');
|
|
45
|
+
$$renderer.push(`<div class="df-calendar-wrapper df-calendar-ssr-placeholder"></div>`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
$$renderer.push(`<!--]-->`);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function useCalendarApp(config) {
|
|
53
|
+
const app = new CalendarApp(config);
|
|
54
|
+
const stateStore = writable({
|
|
55
|
+
currentView: app.state.currentView,
|
|
56
|
+
currentDate: app.state.currentDate,
|
|
57
|
+
events: app.getEvents()
|
|
58
|
+
});
|
|
59
|
+
app.subscribe((updatedApp) => {
|
|
60
|
+
stateStore.set({
|
|
61
|
+
currentView: updatedApp.state.currentView,
|
|
62
|
+
currentDate: updatedApp.state.currentDate,
|
|
63
|
+
events: updatedApp.getEvents()
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
const result = {
|
|
67
|
+
app,
|
|
68
|
+
get currentView() {
|
|
69
|
+
let val;
|
|
70
|
+
stateStore.subscribe((s) => val = s.currentView)();
|
|
71
|
+
return val;
|
|
72
|
+
},
|
|
73
|
+
get currentDate() {
|
|
74
|
+
let val;
|
|
75
|
+
stateStore.subscribe((s) => val = s.currentDate)();
|
|
76
|
+
return val;
|
|
77
|
+
},
|
|
78
|
+
get events() {
|
|
79
|
+
let val;
|
|
80
|
+
stateStore.subscribe((s) => val = s.events)();
|
|
81
|
+
return val;
|
|
82
|
+
},
|
|
83
|
+
applyEventsChanges: app.applyEventsChanges.bind(app),
|
|
84
|
+
changeView: app.changeView.bind(app),
|
|
85
|
+
setCurrentDate: app.setCurrentDate.bind(app),
|
|
86
|
+
addEvent: app.addEvent.bind(app),
|
|
87
|
+
updateEvent: app.updateEvent.bind(app),
|
|
88
|
+
deleteEvent: app.deleteEvent.bind(app),
|
|
89
|
+
undo: app.undo.bind(app),
|
|
90
|
+
goToToday: app.goToToday.bind(app),
|
|
91
|
+
goToPrevious: app.goToPrevious.bind(app),
|
|
92
|
+
goToNext: app.goToNext.bind(app),
|
|
93
|
+
selectDate: app.selectDate.bind(app),
|
|
94
|
+
getCalendars: app.getCalendars.bind(app),
|
|
95
|
+
createCalendar: app.createCalendar.bind(app),
|
|
96
|
+
mergeCalendars: app.mergeCalendars.bind(app),
|
|
97
|
+
setCalendarVisibility: app.setCalendarVisibility.bind(app),
|
|
98
|
+
setAllCalendarsVisibility: app.setAllCalendarsVisibility.bind(app),
|
|
99
|
+
getAllEvents: app.getAllEvents.bind(app),
|
|
100
|
+
highlightEvent: app.highlightEvent.bind(app),
|
|
101
|
+
setVisibleMonth: app.setVisibleMonth.bind(app),
|
|
102
|
+
getVisibleMonth: app.getVisibleMonth.bind(app),
|
|
103
|
+
get sidebarConfig() {
|
|
104
|
+
return app.getSidebarConfig();
|
|
105
|
+
},
|
|
106
|
+
get readOnlyConfig() {
|
|
107
|
+
return app.getReadOnlyConfig();
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { DayFlowCalendar, DayFlowCalendar as default, useCalendarApp };
|
|
114
|
+
//# sourceMappingURL=index.ssr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.ssr.js","sources":["../src/DayFlowCalendar.svelte","../src/useCalendarApp.ts"],"sourcesContent":["<script lang=\"ts\">\n import { onMount, onDestroy, tick } from 'svelte';\n import {\n CalendarRenderer,\n type ICalendarApp,\n type UseCalendarAppReturn,\n type CustomRendering,\n } from '@dayflow/core';\n\n let {\n calendar,\n eventContent = null,\n eventDetailContent = null,\n eventDetailDialog = null,\n headerContent = null,\n createCalendarDialog = null,\n titleBarSlot = null,\n colorPicker = null,\n colorPickerWrapper = null,\n } = $props<{\n calendar: ICalendarApp | UseCalendarAppReturn;\n eventContent?: any;\n eventDetailContent?: any;\n eventDetailDialog?: any;\n headerContent?: any;\n createCalendarDialog?: any;\n titleBarSlot?: any;\n colorPicker?: any;\n colorPickerWrapper?: any;\n }>();\n\n let container: HTMLElement | undefined = $state();\n let renderer: CalendarRenderer | undefined;\n let customRenderings: CustomRendering[] = $state([]);\n let unsubscribe: (() => void) | undefined;\n let mounted = $state(false);\n\n // Guard for browser environment\n const isBrowser = typeof window !== 'undefined';\n\n const app = $derived((calendar as any).app || calendar);\n\n const renderProps = $derived({\n eventContent,\n eventDetailContent,\n eventDetailDialog,\n headerContent,\n createCalendarDialog,\n titleBarSlot,\n colorPicker,\n colorPickerWrapper,\n } as Record<string, any>);\n\n onMount(async () => {\n if (!container) return;\n\n await tick();\n\n const { CalendarRenderer } = await import('@dayflow/core');\n\n renderer = new CalendarRenderer(app);\n renderer.mount(container);\n\n unsubscribe = renderer.getCustomRenderingStore().subscribe(renderings => {\n customRenderings = Array.from(renderings.values());\n });\n\n const activeOverrides = Object.keys(renderProps).filter(\n key => renderProps[key] !== null\n );\n renderer.getCustomRenderingStore().setOverrides(activeOverrides);\n\n mounted = true;\n });\n\n onDestroy(() => {\n if (unsubscribe) unsubscribe();\n if (renderer) renderer.unmount();\n });\n\n function portal(node: HTMLElement, target: HTMLElement) {\n if (!target || !node || !isBrowser) return;\n target.appendChild(node);\n return {\n destroy() {\n if (node.parentNode === target) {\n target.removeChild(node);\n }\n },\n };\n }\n</script>\n\n{#if isBrowser}\n <div bind:this={container} class=\"df-calendar-wrapper\"></div>\n\n {#if mounted}\n {#each customRenderings as rendering (rendering.id)}\n {@const Component = renderProps[rendering.generatorName]}\n {#if Component && rendering.containerEl}\n <div use:portal={rendering.containerEl}>\n <Component {...rendering.generatorArgs} />\n </div>\n {/if}\n {/each}\n {/if}\n{:else}\n <!-- SSR Placeholder -->\n <div class=\"df-calendar-wrapper df-calendar-ssr-placeholder\"></div>\n{/if}\n","import { writable } from 'svelte/store';\nimport type { Writable } from 'svelte/store';\nimport { CalendarApp } from '@dayflow/core';\nimport type {\n CalendarAppConfig,\n UseCalendarAppReturn,\n ICalendarApp,\n} from '@dayflow/core';\n\nexport function useCalendarApp(\n config: CalendarAppConfig\n): UseCalendarAppReturn {\n const app = new CalendarApp(config);\n\n // Create a store for the parts of state we want to be reactive in Svelte\n const stateStore = writable({\n currentView: app.state.currentView,\n currentDate: app.state.currentDate,\n events: app.getEvents(),\n });\n\n const unsubscribe = app.subscribe(updatedApp => {\n stateStore.set({\n currentView: updatedApp.state.currentView,\n currentDate: updatedApp.state.currentDate,\n events: updatedApp.getEvents(),\n });\n });\n\n // Proxy the state properties\n const result = {\n app,\n get currentView() {\n let val;\n stateStore.subscribe(s => (val = s.currentView))();\n return val;\n },\n get currentDate() {\n let val;\n stateStore.subscribe(s => (val = s.currentDate))();\n return val;\n },\n get events() {\n let val;\n stateStore.subscribe(s => (val = s.events))();\n return val;\n },\n\n applyEventsChanges: app.applyEventsChanges.bind(app),\n changeView: app.changeView.bind(app),\n setCurrentDate: app.setCurrentDate.bind(app),\n addEvent: app.addEvent.bind(app),\n updateEvent: app.updateEvent.bind(app),\n deleteEvent: app.deleteEvent.bind(app),\n undo: app.undo.bind(app),\n goToToday: app.goToToday.bind(app),\n goToPrevious: app.goToPrevious.bind(app),\n goToNext: app.goToNext.bind(app),\n selectDate: app.selectDate.bind(app),\n getCalendars: app.getCalendars.bind(app),\n createCalendar: app.createCalendar.bind(app),\n mergeCalendars: app.mergeCalendars.bind(app),\n setCalendarVisibility: app.setCalendarVisibility.bind(app),\n setAllCalendarsVisibility: app.setAllCalendarsVisibility.bind(app),\n getAllEvents: app.getAllEvents.bind(app),\n highlightEvent: app.highlightEvent.bind(app),\n setVisibleMonth: app.setVisibleMonth.bind(app),\n getVisibleMonth: app.getVisibleMonth.bind(app),\n get sidebarConfig() {\n return app.getSidebarConfig();\n },\n get readOnlyConfig() {\n return app.getReadOnlyConfig();\n },\n } as unknown as UseCalendarAppReturn;\n\n return result;\n}\n"],"names":[],"mappings":";;;;;;;;sCAAA;;;;;;;;;;;;;;;;;;;;;;;;;MA6FK,SAAS,EAAA;;;;;;;;;;;;;;;AAFN,CAAA,CAAA,CAAA;;;AClFD,SAAS,eACd,MAAA,EACsB;AACtB,EAAA,MAAM,GAAA,GAAM,IAAI,WAAA,CAAY,MAAM,CAAA;AAGlC,EAAA,MAAM,aAAa,QAAA,CAAS;AAAA,IAC1B,WAAA,EAAa,IAAI,KAAA,CAAM,WAAA;AAAA,IACvB,WAAA,EAAa,IAAI,KAAA,CAAM,WAAA;AAAA,IACvB,MAAA,EA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AA,IAC9B,CAAA;AAAA,IACA,IAAI,cAAA,GAAiB;AACnB,MAAA,OAAO,IAAI,iBAAA,EAAkB;AAAA,IAC/B;AAAA,GACF;AAEA,EAAA,OAAO,MAAA;AACT;;;;"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
declare module "@dayflow/svelte" {
|
|
2
|
+
import { SvelteComponent } from "svelte";
|
|
3
|
+
import {
|
|
4
|
+
CalendarApp,
|
|
5
|
+
CalendarAppConfig,
|
|
6
|
+
UseCalendarAppReturn,
|
|
7
|
+
CalendarRegistry,
|
|
8
|
+
createDragPlugin,
|
|
9
|
+
createEventsPlugin,
|
|
10
|
+
createDayView,
|
|
11
|
+
createWeekView,
|
|
12
|
+
createMonthView,
|
|
13
|
+
createYearView,
|
|
14
|
+
ViewType
|
|
15
|
+
} from "@dayflow/core";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Svelte store based hook for DayFlow
|
|
19
|
+
*/
|
|
20
|
+
export function useCalendarApp(config: CalendarAppConfig): UseCalendarAppReturn;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* DayFlow Calendar Svelte Component
|
|
24
|
+
*/
|
|
25
|
+
export class DayFlowCalendar extends SvelteComponent<any, any, any> {}
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
CalendarApp,
|
|
29
|
+
CalendarRegistry,
|
|
30
|
+
createDragPlugin,
|
|
31
|
+
createEventsPlugin,
|
|
32
|
+
createDayView,
|
|
33
|
+
createWeekView,
|
|
34
|
+
createMonthView,
|
|
35
|
+
createYearView,
|
|
36
|
+
ViewType
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default DayFlowCalendar;
|
|
40
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dayflow/svelte",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Svelte adapter for DayFlow calendar",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"svelte": "src/index.ts",
|
|
9
|
+
"types": "index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./index.d.ts",
|
|
13
|
+
"svelte": "./src/index.ts",
|
|
14
|
+
"browser": "./dist/index.js",
|
|
15
|
+
"ssr": "./dist/index.ssr.js",
|
|
16
|
+
"import": {
|
|
17
|
+
"browser": "./dist/index.js",
|
|
18
|
+
"default": "./dist/index.ssr.js"
|
|
19
|
+
},
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"src",
|
|
26
|
+
"index.d.ts",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "rollup -c",
|
|
31
|
+
"typecheck": "svelte-check"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"svelte": "^4.0.0 || ^5.0.0",
|
|
35
|
+
"@dayflow/core": "workspace:*"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"svelte": "^5.0.0",
|
|
39
|
+
"@dayflow/core": "workspace:*",
|
|
40
|
+
"typescript": "^5.7.2",
|
|
41
|
+
"rollup": "^4.29.1",
|
|
42
|
+
"@rollup/plugin-commonjs": "^28.0.2",
|
|
43
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
44
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
45
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
46
|
+
"rollup-plugin-svelte": "^7.2.2",
|
|
47
|
+
"svelte-preprocess": "^6.0.3",
|
|
48
|
+
"svelte-check": "^4.1.1",
|
|
49
|
+
"@tsconfig/svelte": "^5.0.4",
|
|
50
|
+
"rollup-plugin-esbuild": "^6.2.1",
|
|
51
|
+
"esbuild": "^0.27.3"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount, onDestroy, tick } from 'svelte';
|
|
3
|
+
import {
|
|
4
|
+
CalendarRenderer,
|
|
5
|
+
type ICalendarApp,
|
|
6
|
+
type UseCalendarAppReturn,
|
|
7
|
+
type CustomRendering,
|
|
8
|
+
} from '@dayflow/core';
|
|
9
|
+
|
|
10
|
+
let {
|
|
11
|
+
calendar,
|
|
12
|
+
eventContent = null,
|
|
13
|
+
eventDetailContent = null,
|
|
14
|
+
eventDetailDialog = null,
|
|
15
|
+
headerContent = null,
|
|
16
|
+
createCalendarDialog = null,
|
|
17
|
+
titleBarSlot = null,
|
|
18
|
+
colorPicker = null,
|
|
19
|
+
colorPickerWrapper = null,
|
|
20
|
+
} = $props<{
|
|
21
|
+
calendar: ICalendarApp | UseCalendarAppReturn;
|
|
22
|
+
eventContent?: any;
|
|
23
|
+
eventDetailContent?: any;
|
|
24
|
+
eventDetailDialog?: any;
|
|
25
|
+
headerContent?: any;
|
|
26
|
+
createCalendarDialog?: any;
|
|
27
|
+
titleBarSlot?: any;
|
|
28
|
+
colorPicker?: any;
|
|
29
|
+
colorPickerWrapper?: any;
|
|
30
|
+
}>();
|
|
31
|
+
|
|
32
|
+
let container: HTMLElement | undefined = $state();
|
|
33
|
+
let renderer: CalendarRenderer | undefined;
|
|
34
|
+
let customRenderings: CustomRendering[] = $state([]);
|
|
35
|
+
let unsubscribe: (() => void) | undefined;
|
|
36
|
+
let mounted = $state(false);
|
|
37
|
+
|
|
38
|
+
// Guard for browser environment
|
|
39
|
+
const isBrowser = typeof window !== 'undefined';
|
|
40
|
+
|
|
41
|
+
const app = $derived((calendar as any).app || calendar);
|
|
42
|
+
|
|
43
|
+
const renderProps = $derived({
|
|
44
|
+
eventContent,
|
|
45
|
+
eventDetailContent,
|
|
46
|
+
eventDetailDialog,
|
|
47
|
+
headerContent,
|
|
48
|
+
createCalendarDialog,
|
|
49
|
+
titleBarSlot,
|
|
50
|
+
colorPicker,
|
|
51
|
+
colorPickerWrapper,
|
|
52
|
+
} as Record<string, any>);
|
|
53
|
+
|
|
54
|
+
onMount(async () => {
|
|
55
|
+
if (!container) return;
|
|
56
|
+
|
|
57
|
+
await tick();
|
|
58
|
+
|
|
59
|
+
const { CalendarRenderer } = await import('@dayflow/core');
|
|
60
|
+
|
|
61
|
+
renderer = new CalendarRenderer(app);
|
|
62
|
+
renderer.mount(container);
|
|
63
|
+
|
|
64
|
+
unsubscribe = renderer.getCustomRenderingStore().subscribe(renderings => {
|
|
65
|
+
customRenderings = Array.from(renderings.values());
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const activeOverrides = Object.keys(renderProps).filter(
|
|
69
|
+
key => renderProps[key] !== null
|
|
70
|
+
);
|
|
71
|
+
renderer.getCustomRenderingStore().setOverrides(activeOverrides);
|
|
72
|
+
|
|
73
|
+
mounted = true;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
onDestroy(() => {
|
|
77
|
+
if (unsubscribe) unsubscribe();
|
|
78
|
+
if (renderer) renderer.unmount();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
function portal(node: HTMLElement, target: HTMLElement) {
|
|
82
|
+
if (!target || !node || !isBrowser) return;
|
|
83
|
+
target.appendChild(node);
|
|
84
|
+
return {
|
|
85
|
+
destroy() {
|
|
86
|
+
if (node.parentNode === target) {
|
|
87
|
+
target.removeChild(node);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
</script>
|
|
93
|
+
|
|
94
|
+
{#if isBrowser}
|
|
95
|
+
<div bind:this={container} class="df-calendar-wrapper"></div>
|
|
96
|
+
|
|
97
|
+
{#if mounted}
|
|
98
|
+
{#each customRenderings as rendering (rendering.id)}
|
|
99
|
+
{@const Component = renderProps[rendering.generatorName]}
|
|
100
|
+
{#if Component && rendering.containerEl}
|
|
101
|
+
<div use:portal={rendering.containerEl}>
|
|
102
|
+
<Component {...rendering.generatorArgs} />
|
|
103
|
+
</div>
|
|
104
|
+
{/if}
|
|
105
|
+
{/each}
|
|
106
|
+
{/if}
|
|
107
|
+
{:else}
|
|
108
|
+
<!-- SSR Placeholder -->
|
|
109
|
+
<div class="df-calendar-wrapper df-calendar-ssr-placeholder"></div>
|
|
110
|
+
{/if}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import DayFlowCalendar from './DayFlowCalendar.svelte';
|
|
2
|
+
export { DayFlowCalendar };
|
|
3
|
+
export { useCalendarApp } from './useCalendarApp';
|
|
4
|
+
export default DayFlowCalendar;
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
CalendarApp,
|
|
8
|
+
CalendarRegistry,
|
|
9
|
+
createDragPlugin,
|
|
10
|
+
createEventsPlugin,
|
|
11
|
+
createDayView,
|
|
12
|
+
createWeekView,
|
|
13
|
+
createMonthView,
|
|
14
|
+
createYearView,
|
|
15
|
+
ViewType,
|
|
16
|
+
} from '@dayflow/core';
|
|
17
|
+
|
|
18
|
+
export * from '@dayflow/core';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { writable } from 'svelte/store';
|
|
2
|
+
import type { Writable } from 'svelte/store';
|
|
3
|
+
import { CalendarApp } from '@dayflow/core';
|
|
4
|
+
import type {
|
|
5
|
+
CalendarAppConfig,
|
|
6
|
+
UseCalendarAppReturn,
|
|
7
|
+
ICalendarApp,
|
|
8
|
+
} from '@dayflow/core';
|
|
9
|
+
|
|
10
|
+
export function useCalendarApp(
|
|
11
|
+
config: CalendarAppConfig
|
|
12
|
+
): UseCalendarAppReturn {
|
|
13
|
+
const app = new CalendarApp(config);
|
|
14
|
+
|
|
15
|
+
// Create a store for the parts of state we want to be reactive in Svelte
|
|
16
|
+
const stateStore = writable({
|
|
17
|
+
currentView: app.state.currentView,
|
|
18
|
+
currentDate: app.state.currentDate,
|
|
19
|
+
events: app.getEvents(),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const unsubscribe = app.subscribe(updatedApp => {
|
|
23
|
+
stateStore.set({
|
|
24
|
+
currentView: updatedApp.state.currentView,
|
|
25
|
+
currentDate: updatedApp.state.currentDate,
|
|
26
|
+
events: updatedApp.getEvents(),
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Proxy the state properties
|
|
31
|
+
const result = {
|
|
32
|
+
app,
|
|
33
|
+
get currentView() {
|
|
34
|
+
let val;
|
|
35
|
+
stateStore.subscribe(s => (val = s.currentView))();
|
|
36
|
+
return val;
|
|
37
|
+
},
|
|
38
|
+
get currentDate() {
|
|
39
|
+
let val;
|
|
40
|
+
stateStore.subscribe(s => (val = s.currentDate))();
|
|
41
|
+
return val;
|
|
42
|
+
},
|
|
43
|
+
get events() {
|
|
44
|
+
let val;
|
|
45
|
+
stateStore.subscribe(s => (val = s.events))();
|
|
46
|
+
return val;
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
applyEventsChanges: app.applyEventsChanges.bind(app),
|
|
50
|
+
changeView: app.changeView.bind(app),
|
|
51
|
+
setCurrentDate: app.setCurrentDate.bind(app),
|
|
52
|
+
addEvent: app.addEvent.bind(app),
|
|
53
|
+
updateEvent: app.updateEvent.bind(app),
|
|
54
|
+
deleteEvent: app.deleteEvent.bind(app),
|
|
55
|
+
undo: app.undo.bind(app),
|
|
56
|
+
goToToday: app.goToToday.bind(app),
|
|
57
|
+
goToPrevious: app.goToPrevious.bind(app),
|
|
58
|
+
goToNext: app.goToNext.bind(app),
|
|
59
|
+
selectDate: app.selectDate.bind(app),
|
|
60
|
+
getCalendars: app.getCalendars.bind(app),
|
|
61
|
+
createCalendar: app.createCalendar.bind(app),
|
|
62
|
+
mergeCalendars: app.mergeCalendars.bind(app),
|
|
63
|
+
setCalendarVisibility: app.setCalendarVisibility.bind(app),
|
|
64
|
+
setAllCalendarsVisibility: app.setAllCalendarsVisibility.bind(app),
|
|
65
|
+
getAllEvents: app.getAllEvents.bind(app),
|
|
66
|
+
highlightEvent: app.highlightEvent.bind(app),
|
|
67
|
+
setVisibleMonth: app.setVisibleMonth.bind(app),
|
|
68
|
+
getVisibleMonth: app.getVisibleMonth.bind(app),
|
|
69
|
+
get sidebarConfig() {
|
|
70
|
+
return app.getSidebarConfig();
|
|
71
|
+
},
|
|
72
|
+
get readOnlyConfig() {
|
|
73
|
+
return app.getReadOnlyConfig();
|
|
74
|
+
},
|
|
75
|
+
} as unknown as UseCalendarAppReturn;
|
|
76
|
+
|
|
77
|
+
return result;
|
|
78
|
+
}
|