@nomideusz/svelte-calendar 1.2.0 → 1.4.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 +143 -93
- package/dist/adapters/mapped.d.ts +7 -7
- package/dist/adapters/mapped.js +5 -2
- package/dist/adapters/memory.d.ts +7 -6
- package/dist/adapters/memory.js +3 -4
- package/dist/adapters/recurring.d.ts +6 -6
- package/dist/adapters/recurring.js +12 -14
- package/dist/calendar/Calendar.svelte +226 -304
- package/dist/calendar/Calendar.svelte.d.ts +1 -1
- package/dist/primitives/DayHeader.svelte +7 -7
- package/dist/primitives/EmptySlot.svelte +6 -6
- package/dist/primitives/EventBlock.svelte +19 -19
- package/dist/primitives/FloatingPanel.svelte +4 -4
- package/dist/primitives/NowIndicator.svelte +5 -5
- package/dist/primitives/TimeGutter.svelte +4 -4
- package/dist/theme/auto.d.ts +5 -0
- package/dist/theme/auto.js +16 -3
- package/dist/theme/presets.d.ts +2 -2
- package/dist/theme/presets.js +2 -2
- package/dist/views/agenda/AgendaDay.svelte +207 -323
- package/dist/views/agenda/AgendaWeek.svelte +145 -222
- package/dist/views/mobile/MobileDay.svelte +79 -60
- package/dist/views/mobile/MobileWeek.svelte +48 -38
- package/dist/views/month/MonthGrid.svelte +92 -36
- package/dist/views/planner/PlannerScroll.svelte +78 -72
- package/dist/views/planner/PlannerWeek.svelte +145 -90
- package/dist/views/shared/context.svelte.d.ts +2 -0
- package/dist/views/shared/context.svelte.js +1 -0
- package/dist/views/shared/format.d.ts +3 -0
- package/dist/views/shared/format.js +10 -1
- package/package.json +1 -1
- package/widget/widget.js +816 -725
|
@@ -95,16 +95,16 @@ export interface MappedAdapterOptions<T = Record<string, unknown>> {
|
|
|
95
95
|
*/
|
|
96
96
|
includeData?: string[] | '*';
|
|
97
97
|
/**
|
|
98
|
-
* When true
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* @default true
|
|
98
|
+
* When true, ignore source colors and auto-assign from the palette
|
|
99
|
+
* (`VIVID_PALETTE` unless `palette` is given) grouped by category / title.
|
|
100
|
+
* By default source colors are kept, and events without one draw in
|
|
101
|
+
* `--dt-event` (ink) unless a `palette` is given to fill them.
|
|
102
|
+
* @default false (since 1.4; was true)
|
|
103
103
|
*/
|
|
104
104
|
autoColor?: boolean;
|
|
105
105
|
/**
|
|
106
|
-
* Color palette used
|
|
107
|
-
*
|
|
106
|
+
* Color palette used to fill events without a source color
|
|
107
|
+
* (or every event when `autoColor: true`). Off by default.
|
|
108
108
|
*/
|
|
109
109
|
palette?: readonly string[];
|
|
110
110
|
/**
|
package/dist/adapters/mapped.js
CHANGED
|
@@ -139,15 +139,18 @@ function collectData(raw, mappedKeys, include) {
|
|
|
139
139
|
* ```
|
|
140
140
|
*/
|
|
141
141
|
export function createMappedAdapter(sourceData, options = {}) {
|
|
142
|
-
const { fields, mapEvent: customMapper, includeData = '*', autoColor =
|
|
142
|
+
const { fields, mapEvent: customMapper, includeData = '*', autoColor = false, palette = autoColor ? VIVID_PALETTE : undefined, readOnly = true, } = options;
|
|
143
143
|
// Build the internal event list
|
|
144
144
|
const events = [];
|
|
145
145
|
const colorAssignments = new Map();
|
|
146
146
|
let colorIndex = 0;
|
|
147
147
|
function resolveColor(ev) {
|
|
148
|
-
//
|
|
148
|
+
// autoColor: always assign from the palette (ignore source color).
|
|
149
|
+
// Otherwise keep the source color; fill only when a palette is given.
|
|
149
150
|
if (!autoColor && ev.color)
|
|
150
151
|
return ev.color;
|
|
152
|
+
if (!palette?.length)
|
|
153
|
+
return ev.color;
|
|
151
154
|
const key = ev.category ?? ev.title;
|
|
152
155
|
if (!colorAssignments.has(key)) {
|
|
153
156
|
colorAssignments.set(key, palette[colorIndex % palette.length]);
|
|
@@ -2,21 +2,22 @@
|
|
|
2
2
|
* In-memory adapter — the default for demos and testing.
|
|
3
3
|
*
|
|
4
4
|
* Events are stored in a plain array. No persistence across page loads.
|
|
5
|
-
* Events without a `color`
|
|
6
|
-
*
|
|
5
|
+
* Events without a `color` stay uncoloured and draw in `--dt-event` (ink).
|
|
6
|
+
* Pass `palette` to auto-assign colours instead, grouped by `category` or
|
|
7
|
+
* `title` so related events share one.
|
|
7
8
|
*
|
|
8
9
|
* Usage:
|
|
9
10
|
* import { createMemoryAdapter } from './';
|
|
10
11
|
* const adapter = createMemoryAdapter(initialEvents);
|
|
11
|
-
* const adapter = createMemoryAdapter(initialEvents, { palette:
|
|
12
|
+
* const adapter = createMemoryAdapter(initialEvents, { palette: VIVID_PALETTE });
|
|
12
13
|
*/
|
|
13
14
|
import type { TimelineEvent } from '../core/types.js';
|
|
14
15
|
import type { CalendarAdapter } from './types.js';
|
|
15
16
|
export interface MemoryAdapterOptions {
|
|
16
17
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
18
|
+
* Colour palette for auto-colouring events that have no `color`.
|
|
19
|
+
* Off by default (events draw in `--dt-event`). Pass `VIVID_PALETTE`
|
|
20
|
+
* for the pre-1.4 look, or `generatePalette(accent)` for theme-harmonious colours.
|
|
20
21
|
*/
|
|
21
22
|
palette?: readonly string[];
|
|
22
23
|
}
|
package/dist/adapters/memory.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { VIVID_PALETTE } from '../core/palette.js';
|
|
2
1
|
import { overlapsRange } from '../core/time.js';
|
|
3
2
|
import { EventNotFoundError } from './errors.js';
|
|
4
3
|
let counter = 0;
|
|
@@ -7,12 +6,12 @@ function uid() {
|
|
|
7
6
|
}
|
|
8
7
|
export function createMemoryAdapter(initial = [], options) {
|
|
9
8
|
const events = [...initial];
|
|
10
|
-
const palette = options?.palette
|
|
11
|
-
//
|
|
9
|
+
const palette = options?.palette;
|
|
10
|
+
// Opt-in auto-color: assign from the palette by category/title
|
|
12
11
|
const colorAssignments = new Map();
|
|
13
12
|
let colorIndex = 0;
|
|
14
13
|
function resolveColor(ev) {
|
|
15
|
-
if (ev.color)
|
|
14
|
+
if (ev.color || !palette?.length)
|
|
16
15
|
return ev.color;
|
|
17
16
|
const key = ev.category ?? ev.title;
|
|
18
17
|
if (!colorAssignments.has(key)) {
|
|
@@ -74,10 +74,10 @@ export interface RecurringAdapterOptions {
|
|
|
74
74
|
/** Start weeks on Monday (default: true) */
|
|
75
75
|
mondayStart?: boolean;
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
77
|
+
* Colour palette for auto-colouring events that have no `color`.
|
|
78
|
+
* Off by default (events draw in `--dt-event`). Pass `VIVID_PALETTE`
|
|
79
|
+
* for the pre-1.4 look, `generatePalette('#yourAccent')` for
|
|
80
|
+
* theme-harmonious colours, or your own array of colours.
|
|
81
81
|
*/
|
|
82
82
|
palette?: readonly string[];
|
|
83
83
|
/**
|
|
@@ -95,8 +95,8 @@ export interface RecurringAdapterOptions {
|
|
|
95
95
|
* Create a CalendarAdapter that projects recurring events onto concrete
|
|
96
96
|
* dates for whatever range the calendar requests.
|
|
97
97
|
*
|
|
98
|
-
* Events without a `color`
|
|
99
|
-
* grouped by `category` or `title
|
|
98
|
+
* Events without a `color` draw in `--dt-event` (ink) unless `palette` is
|
|
99
|
+
* given; then they are auto-assigned one, grouped by `category` or `title`.
|
|
100
100
|
*
|
|
101
101
|
* Read-only by default — create/update/delete throw.
|
|
102
102
|
*/
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { startOfWeek, addDaysMs, diffDays, DAY_MS, overlapsRange } from '../core/time.js';
|
|
2
|
-
import { VIVID_PALETTE } from '../core/palette.js';
|
|
3
2
|
import { CalendarReadOnlyError, EventNotFoundError } from './errors.js';
|
|
4
3
|
// ── Helpers ─────────────────────────────────────────────
|
|
5
4
|
/** Parse "HH:MM" into [hours, minutes] */
|
|
@@ -234,32 +233,31 @@ function projectMonthly(rec, range, startDate, effectiveUntil, out) {
|
|
|
234
233
|
}
|
|
235
234
|
}
|
|
236
235
|
// ── Adapter factory ─────────────────────────────────────
|
|
237
|
-
/** Default palette for auto-coloring */
|
|
238
|
-
const PALETTE = VIVID_PALETTE;
|
|
239
236
|
/**
|
|
240
237
|
* Create a CalendarAdapter that projects recurring events onto concrete
|
|
241
238
|
* dates for whatever range the calendar requests.
|
|
242
239
|
*
|
|
243
|
-
* Events without a `color`
|
|
244
|
-
* grouped by `category` or `title
|
|
240
|
+
* Events without a `color` draw in `--dt-event` (ink) unless `palette` is
|
|
241
|
+
* given; then they are auto-assigned one, grouped by `category` or `title`.
|
|
245
242
|
*
|
|
246
243
|
* Read-only by default — create/update/delete throw.
|
|
247
244
|
*/
|
|
248
245
|
export function createRecurringAdapter(schedule, options = {}) {
|
|
249
246
|
const { mondayStart = true, palette, movable = false } = options;
|
|
250
|
-
const colors = palette?.length ? palette :
|
|
247
|
+
const colors = palette?.length ? palette : undefined;
|
|
251
248
|
// Auto-color: assign from palette by category/title
|
|
252
249
|
const colorAssignments = new Map();
|
|
253
250
|
let colorIndex = 0;
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
colorAssignments.
|
|
260
|
-
|
|
251
|
+
if (colors)
|
|
252
|
+
for (const rec of schedule) {
|
|
253
|
+
if (rec.color)
|
|
254
|
+
continue;
|
|
255
|
+
const key = rec.category ?? rec.title;
|
|
256
|
+
if (!colorAssignments.has(key)) {
|
|
257
|
+
colorAssignments.set(key, colors[colorIndex % colors.length]);
|
|
258
|
+
colorIndex++;
|
|
259
|
+
}
|
|
261
260
|
}
|
|
262
|
-
}
|
|
263
261
|
function resolveColor(rec) {
|
|
264
262
|
if (rec.color)
|
|
265
263
|
return rec.color;
|