@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.
@@ -95,16 +95,16 @@ export interface MappedAdapterOptions<T = Record<string, unknown>> {
95
95
  */
96
96
  includeData?: string[] | '*';
97
97
  /**
98
- * When true (default), ignore source colors and auto-assign from
99
- * the palette grouped by category / title. This keeps the calendar
100
- * visually consistent regardless of the upstream source.
101
- * Set to `false` to preserve the original colors from the data.
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 for auto-coloring.
107
- * Defaults to VIVID_PALETTE.
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
  /**
@@ -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 = true, palette = VIVID_PALETTE, readOnly = true, } = options;
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
- // When autoColor is on, always assign from palette (ignore source color)
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` are auto-assigned one from a palette,
6
- * grouped by `category` or `title` so related events share a color.
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: myColors });
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
- * Custom color palette for auto-coloring events.
18
- * Defaults to VIVID_PALETTE. Pass `generatePalette(accent)` to
19
- * make event colors adapt to your theme.
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
  }
@@ -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 ?? VIVID_PALETTE;
11
- // Auto-color: assign from vivid palette by category/title
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
- * Custom color palette for auto-coloring events.
78
- * Pass `generatePalette('#yourAccent')` to get theme-harmonious colors,
79
- * or provide your own array of hex strings.
80
- * Defaults to the built-in vivid palette.
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` are auto-assigned one from a vivid palette,
99
- * grouped by `category` or `title` so related events share a color.
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` are auto-assigned one from a vivid palette,
244
- * grouped by `category` or `title` so related events share a color.
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 : 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
- for (const rec of schedule) {
255
- if (rec.color)
256
- continue;
257
- const key = rec.category ?? rec.title;
258
- if (!colorAssignments.has(key)) {
259
- colorAssignments.set(key, colors[colorIndex % colors.length]);
260
- colorIndex++;
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;