@nomideusz/svelte-calendar 0.2.3 → 0.3.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 +207 -6
- package/dist/adapters/index.d.ts +3 -0
- package/dist/adapters/index.js +1 -0
- package/dist/adapters/memory.d.ts +7 -1
- package/dist/adapters/memory.js +35 -4
- package/dist/adapters/recurring.d.ts +39 -0
- package/dist/adapters/recurring.js +117 -0
- package/dist/calendar/Calendar.svelte +20 -5
- package/dist/calendar/Calendar.svelte.d.ts +4 -0
- package/dist/core/types.d.ts +4 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/primitives/EventBlock.svelte +42 -0
- package/dist/theme/index.d.ts +1 -1
- package/dist/theme/index.js +1 -1
- package/dist/theme/presets.d.ts +10 -15
- package/dist/theme/presets.js +5 -11
- package/dist/views/day/DayGrid.svelte +5 -0
- package/dist/views/day/DayGrid.svelte.d.ts +5 -0
- package/dist/views/index.d.ts +1 -0
- package/dist/views/index.js +1 -0
- package/dist/views/schedule/WeekSchedule.svelte +133 -0
- package/dist/views/schedule/WeekSchedule.svelte.d.ts +38 -0
- package/dist/views/schedule/index.d.ts +1 -0
- package/dist/views/schedule/index.js +2 -0
- package/dist/views/settings/Settings.svelte +1 -1
- package/dist/views/week/WeekGrid.svelte +7 -2
- package/dist/views/week/WeekGrid.svelte.d.ts +3 -0
- package/dist/views/week/WeekHeatmap.svelte +12 -5
- package/dist/views/week/WeekHeatmap.svelte.d.ts +5 -1
- package/dist/widget/CalendarWidget.svelte +138 -0
- package/dist/widget/CalendarWidget.svelte.d.ts +23 -0
- package/dist/widget/index.d.ts +1 -0
- package/dist/widget/index.js +1 -0
- package/dist/widget/widget.d.ts +7 -0
- package/dist/widget/widget.js +9 -0
- package/package.json +5 -2
- package/widget/widget.js +260 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
CalendarWidget — self-contained calendar for embedding via <day-calendar> custom element.
|
|
3
|
+
|
|
4
|
+
Accepts simple HTML attributes and wires up the full Calendar with sensible defaults.
|
|
5
|
+
Designed for non-Svelte sites (plain HTML, WordPress, Squarespace, etc.).
|
|
6
|
+
|
|
7
|
+
Usage as custom element:
|
|
8
|
+
<day-calendar
|
|
9
|
+
api="https://myschool.com/api/events"
|
|
10
|
+
theme="neutral"
|
|
11
|
+
view="week-grid"
|
|
12
|
+
height="600"
|
|
13
|
+
locale="en-US"
|
|
14
|
+
></day-calendar>
|
|
15
|
+
-->
|
|
16
|
+
<svelte:options customElement="day-calendar" />
|
|
17
|
+
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import Calendar from '../calendar/Calendar.svelte';
|
|
20
|
+
import type { CalendarView } from '../calendar/Calendar.svelte';
|
|
21
|
+
import { DayGrid } from '../views/day/index.js';
|
|
22
|
+
import { WeekGrid } from '../views/week/index.js';
|
|
23
|
+
import { Agenda } from '../views/agenda/index.js';
|
|
24
|
+
import { WeekHeatmap } from '../views/week/index.js';
|
|
25
|
+
import { DayTimeline } from '../views/day/index.js';
|
|
26
|
+
import { createRestAdapter } from '../adapters/rest.js';
|
|
27
|
+
import { createMemoryAdapter } from '../adapters/memory.js';
|
|
28
|
+
import { presets } from '../theme/presets.js';
|
|
29
|
+
import type { PresetName } from '../theme/presets.js';
|
|
30
|
+
import type { TimelineEvent } from '../core/types.js';
|
|
31
|
+
|
|
32
|
+
interface Props {
|
|
33
|
+
/** REST API base URL — if provided, fetches events from this endpoint */
|
|
34
|
+
api?: string;
|
|
35
|
+
/** JSON string of events for static/inline data (alternative to api) */
|
|
36
|
+
events?: string;
|
|
37
|
+
/** Theme preset name: midnight, parchment, indigo, neutral, bare */
|
|
38
|
+
theme?: string;
|
|
39
|
+
/** Default view ID */
|
|
40
|
+
view?: string;
|
|
41
|
+
/** Calendar height in pixels */
|
|
42
|
+
height?: string;
|
|
43
|
+
/** BCP 47 locale tag (e.g. 'en-US', 'pl-PL') */
|
|
44
|
+
locale?: string;
|
|
45
|
+
/** Text direction: ltr, rtl, auto */
|
|
46
|
+
dir?: string;
|
|
47
|
+
/** Start week on Monday (default: true) */
|
|
48
|
+
mondaystart?: string;
|
|
49
|
+
/** Custom HTTP headers as JSON string for REST adapter */
|
|
50
|
+
headers?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let {
|
|
54
|
+
api,
|
|
55
|
+
events,
|
|
56
|
+
theme = 'neutral',
|
|
57
|
+
view = 'week-grid',
|
|
58
|
+
height = '600',
|
|
59
|
+
locale,
|
|
60
|
+
dir,
|
|
61
|
+
mondaystart = 'true',
|
|
62
|
+
headers,
|
|
63
|
+
}: Props = $props();
|
|
64
|
+
|
|
65
|
+
// ── Parse attributes ──
|
|
66
|
+
const heightPx = $derived(parseInt(height, 10) || 600);
|
|
67
|
+
const isMondayStart = $derived(mondaystart !== 'false');
|
|
68
|
+
const themeStyle = $derived(
|
|
69
|
+
(presets as Record<string, string>)[theme] ?? presets.neutral
|
|
70
|
+
);
|
|
71
|
+
const dirValue = $derived(
|
|
72
|
+
(dir === 'rtl' || dir === 'ltr' || dir === 'auto') ? dir as 'ltr' | 'rtl' | 'auto' : undefined
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// ── Parse static events from JSON attribute ──
|
|
76
|
+
function parseEvents(json?: string): TimelineEvent[] {
|
|
77
|
+
if (!json) return [];
|
|
78
|
+
try {
|
|
79
|
+
const raw = JSON.parse(json) as Array<Record<string, unknown>>;
|
|
80
|
+
return raw.map((e) => ({
|
|
81
|
+
id: String(e.id ?? crypto.randomUUID()),
|
|
82
|
+
title: String(e.title ?? 'Untitled'),
|
|
83
|
+
start: new Date(e.start as string),
|
|
84
|
+
end: new Date(e.end as string),
|
|
85
|
+
color: e.color ? String(e.color) : undefined,
|
|
86
|
+
}));
|
|
87
|
+
} catch {
|
|
88
|
+
console.warn('[day-calendar] Failed to parse events JSON:', json);
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ── Create adapter ──
|
|
94
|
+
const adapter = $derived.by(() => {
|
|
95
|
+
if (api) {
|
|
96
|
+
const parsedHeaders = headers ? JSON.parse(headers) as Record<string, string> : undefined;
|
|
97
|
+
return createRestAdapter({
|
|
98
|
+
baseUrl: api,
|
|
99
|
+
headers: parsedHeaders,
|
|
100
|
+
mapEvents: (data: unknown) => {
|
|
101
|
+
const arr = Array.isArray(data) ? data : (data as Record<string, unknown>).events as unknown[] ?? [];
|
|
102
|
+
return arr.map((e: unknown) => {
|
|
103
|
+
const ev = e as Record<string, unknown>;
|
|
104
|
+
return {
|
|
105
|
+
id: String(ev.id ?? ''),
|
|
106
|
+
title: String(ev.title ?? 'Untitled'),
|
|
107
|
+
start: new Date(ev.start as string),
|
|
108
|
+
end: new Date(ev.end as string),
|
|
109
|
+
color: ev.color ? String(ev.color) : undefined,
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return createMemoryAdapter(parseEvents(events));
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// ── Default views ──
|
|
119
|
+
const defaultViews: CalendarView[] = [
|
|
120
|
+
{ id: 'day-grid', label: 'Grid', granularity: 'day', component: DayGrid },
|
|
121
|
+
{ id: 'week-grid', label: 'Grid', granularity: 'week', component: WeekGrid },
|
|
122
|
+
{ id: 'day-timeline', label: 'Timeline', granularity: 'day', component: DayTimeline },
|
|
123
|
+
{ id: 'day-agenda', label: 'Agenda', granularity: 'day', component: Agenda, props: { mode: 'day' } },
|
|
124
|
+
{ id: 'week-agenda', label: 'Agenda', granularity: 'week', component: Agenda, props: { mode: 'week' } },
|
|
125
|
+
{ id: 'week-heatmap', label: 'Heatmap', granularity: 'week', component: WeekHeatmap },
|
|
126
|
+
];
|
|
127
|
+
</script>
|
|
128
|
+
|
|
129
|
+
<Calendar
|
|
130
|
+
{adapter}
|
|
131
|
+
views={defaultViews}
|
|
132
|
+
defaultView={view}
|
|
133
|
+
theme={themeStyle}
|
|
134
|
+
height={heightPx}
|
|
135
|
+
mondayStart={isMondayStart}
|
|
136
|
+
dir={dirValue}
|
|
137
|
+
{locale}
|
|
138
|
+
/>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
/** REST API base URL — if provided, fetches events from this endpoint */
|
|
3
|
+
api?: string;
|
|
4
|
+
/** JSON string of events for static/inline data (alternative to api) */
|
|
5
|
+
events?: string;
|
|
6
|
+
/** Theme preset name: midnight, parchment, indigo, neutral, bare */
|
|
7
|
+
theme?: string;
|
|
8
|
+
/** Default view ID */
|
|
9
|
+
view?: string;
|
|
10
|
+
/** Calendar height in pixels */
|
|
11
|
+
height?: string;
|
|
12
|
+
/** BCP 47 locale tag (e.g. 'en-US', 'pl-PL') */
|
|
13
|
+
locale?: string;
|
|
14
|
+
/** Text direction: ltr, rtl, auto */
|
|
15
|
+
dir?: string;
|
|
16
|
+
/** Start week on Monday (default: true) */
|
|
17
|
+
mondaystart?: string;
|
|
18
|
+
/** Custom HTTP headers as JSON string for REST adapter */
|
|
19
|
+
headers?: string;
|
|
20
|
+
}
|
|
21
|
+
declare const CalendarWidget: import("svelte").Component<Props, {}, "">;
|
|
22
|
+
type CalendarWidget = ReturnType<typeof CalendarWidget>;
|
|
23
|
+
export default CalendarWidget;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as CalendarWidget } from './CalendarWidget.svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as CalendarWidget } from './CalendarWidget.svelte';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widget entry point — registers <day-calendar> as a custom element.
|
|
3
|
+
*
|
|
4
|
+
* This file is the entry point for the standalone widget bundle (widget.js).
|
|
5
|
+
* Import it via a <script> tag on any HTML page.
|
|
6
|
+
*/
|
|
7
|
+
import './CalendarWidget.svelte';
|
|
8
|
+
// The Svelte custom element is auto-registered via <svelte:options customElement="day-calendar" />
|
|
9
|
+
// Nothing else needed — the component self-registers when this module is loaded.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nomideusz/svelte-calendar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A themeable, pluggable Svelte 5 calendar with Day and Week views — Grid, Timeline, Agenda, Heatmap.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,10 +11,12 @@
|
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"svelte": "./dist/index.js",
|
|
13
13
|
"default": "./dist/index.js"
|
|
14
|
-
}
|
|
14
|
+
},
|
|
15
|
+
"./widget": "./widget/widget.js"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
17
18
|
"dist",
|
|
19
|
+
"widget",
|
|
18
20
|
"!dist/**/*.test.*",
|
|
19
21
|
"!dist/**/*.spec.*"
|
|
20
22
|
],
|
|
@@ -22,6 +24,7 @@
|
|
|
22
24
|
"dev": "vite dev",
|
|
23
25
|
"build": "vite build",
|
|
24
26
|
"package": "svelte-kit sync && svelte-package",
|
|
27
|
+
"build:widget": "vite build --config vite.config.widget.ts",
|
|
25
28
|
"prepublishOnly": "npm run package",
|
|
26
29
|
"preview": "vite preview",
|
|
27
30
|
"prepare": "svelte-kit sync || echo ''",
|