@reachweb/alpine-calendar 0.1.1 → 0.2.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 +15 -13
- package/dist/alpine-calendar.cdn.js +1 -1
- package/dist/alpine-calendar.cdn.js.map +1 -1
- package/dist/alpine-calendar.css +1 -1
- package/dist/alpine-calendar.es.js +109 -19
- package/dist/alpine-calendar.es.js.map +1 -1
- package/dist/alpine-calendar.umd.js +1 -1
- package/dist/alpine-calendar.umd.js.map +1 -1
- package/dist/core/metadata.d.ts +25 -0
- package/dist/index.d.ts +2 -0
- package/dist/plugin/calendar-component.d.ts +35 -0
- package/package.json +17 -17
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CalendarDate } from './calendar-date';
|
|
2
|
+
/** Metadata that can be attached to individual dates. */
|
|
3
|
+
export interface DateMeta {
|
|
4
|
+
/** Text below the day number (e.g., "$150"). */
|
|
5
|
+
label?: string;
|
|
6
|
+
/** Visual availability state. 'unavailable' disables selection + shows strikethrough. */
|
|
7
|
+
availability?: 'available' | 'unavailable';
|
|
8
|
+
/** CSS color applied as --color-calendar-day-meta on the cell (for dot/label). */
|
|
9
|
+
color?: string;
|
|
10
|
+
/** Custom class(es) added to the day cell. */
|
|
11
|
+
cssClass?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Provider for per-date metadata.
|
|
15
|
+
* Either a static object map keyed by ISO date strings, or a callback.
|
|
16
|
+
*/
|
|
17
|
+
export type DateMetaProvider = ((date: CalendarDate) => DateMeta | undefined) | Record<string, DateMeta>;
|
|
18
|
+
/**
|
|
19
|
+
* Normalize a DateMetaProvider into a consistent callback form.
|
|
20
|
+
*
|
|
21
|
+
* - `undefined`/`null` → returns a no-op that always returns `undefined`
|
|
22
|
+
* - function → pass through
|
|
23
|
+
* - object map → wrap in `(date) => map[date.toISO()]`
|
|
24
|
+
*/
|
|
25
|
+
export declare function normalizeDateMeta(provider: DateMetaProvider | undefined | null): (date: CalendarDate) => DateMeta | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ export type { Selection } from './core/selection';
|
|
|
30
30
|
export { createDateConstraint, createRangeValidator, createDisabledReasons, isDateDisabled, } from './core/constraints';
|
|
31
31
|
export type { DateConstraintOptions, DateConstraintProperties, DateConstraintRule, ConstraintMessages, } from './core/constraints';
|
|
32
32
|
export type { CalendarConfigRule, RangePreset } from './plugin/calendar-component';
|
|
33
|
+
export { normalizeDateMeta } from './core/metadata';
|
|
34
|
+
export type { DateMeta, DateMetaProvider } from './core/metadata';
|
|
33
35
|
export { presetToday, presetYesterday, presetLastNDays, presetThisWeek, presetLastWeek, presetThisMonth, presetLastMonth, presetThisYear, presetLastYear, } from './core/presets';
|
|
34
36
|
export { parseDate, parseDateRange, parseDateMultiple } from './input/parser';
|
|
35
37
|
export { formatDate, formatRange, formatMultiple } from './input/formatter';
|
|
@@ -3,6 +3,7 @@ import type { ConstraintMessages } from '../core/constraints';
|
|
|
3
3
|
import type { DayCell, MonthGrid, MonthCell, YearCell } from '../core/grid';
|
|
4
4
|
import type { Selection } from '../core/selection';
|
|
5
5
|
import type { RangePreset } from '../core/presets';
|
|
6
|
+
import type { DateMeta, DateMetaProvider } from '../core/metadata';
|
|
6
7
|
/** Period-specific constraint rule (string-based for Alpine/HTML config). */
|
|
7
8
|
export interface CalendarConfigRule {
|
|
8
9
|
/** Start of the period (ISO string). Required unless `months` is set. */
|
|
@@ -128,6 +129,8 @@ export interface CalendarConfig {
|
|
|
128
129
|
/** Whether this click would select or deselect the date. */
|
|
129
130
|
action: 'select' | 'deselect';
|
|
130
131
|
}) => boolean | undefined;
|
|
132
|
+
/** Per-date metadata (labels, availability, colors). Static map or callback. */
|
|
133
|
+
dateMetadata?: DateMetaProvider;
|
|
131
134
|
/** Custom messages for disabled-date tooltips. Overrides default English strings. */
|
|
132
135
|
constraintMessages?: ConstraintMessages;
|
|
133
136
|
/** Auto-render template when no `.rc-calendar` exists in the container. Default: true. Set false to require manual template. */
|
|
@@ -199,6 +202,10 @@ export declare function createCalendarData(config?: CalendarConfig, Alpine?: {
|
|
|
199
202
|
* re-evaluates class bindings without needing a full grid rebuild.
|
|
200
203
|
*/
|
|
201
204
|
_selectionRev: number;
|
|
205
|
+
_getDateMeta: (date: CalendarDate) => DateMeta | undefined;
|
|
206
|
+
_metadataRev: number;
|
|
207
|
+
/** Check if a date is effectively disabled (constraint OR metadata unavailability). */
|
|
208
|
+
_isEffectivelyDisabled(d: CalendarDate): boolean;
|
|
202
209
|
_statusMessage: string;
|
|
203
210
|
readonly selectedDates: CalendarDate[];
|
|
204
211
|
readonly formattedValue: string;
|
|
@@ -299,6 +306,20 @@ export declare function createCalendarData(config?: CalendarConfig, Alpine?: {
|
|
|
299
306
|
date: CalendarDate;
|
|
300
307
|
isDisabled: boolean;
|
|
301
308
|
}): string;
|
|
309
|
+
/**
|
|
310
|
+
* Get metadata for a day cell. Returns `DateMeta | undefined`.
|
|
311
|
+
* Reads `_metadataRev` for Alpine reactivity.
|
|
312
|
+
*/
|
|
313
|
+
dayMeta(cell: {
|
|
314
|
+
date: CalendarDate;
|
|
315
|
+
}): DateMeta | undefined;
|
|
316
|
+
/**
|
|
317
|
+
* Get inline style string for a day cell.
|
|
318
|
+
* Sets `--color-calendar-day-meta` when the metadata has a custom color.
|
|
319
|
+
*/
|
|
320
|
+
dayStyle(cell: {
|
|
321
|
+
date: CalendarDate;
|
|
322
|
+
}): string;
|
|
302
323
|
/**
|
|
303
324
|
* Bind an input element to the calendar.
|
|
304
325
|
*
|
|
@@ -452,6 +473,20 @@ export declare function createCalendarData(config?: CalendarConfig, Alpine?: {
|
|
|
452
473
|
* ```
|
|
453
474
|
*/
|
|
454
475
|
updateConstraints(updates: Partial<CalendarConfig>): void;
|
|
476
|
+
/**
|
|
477
|
+
* Update the date metadata provider at runtime.
|
|
478
|
+
*
|
|
479
|
+
* Normalizes the provider, bumps the reactive counter, and rebuilds
|
|
480
|
+
* the day grid (since unavailability affects disabled state).
|
|
481
|
+
*
|
|
482
|
+
* Usage:
|
|
483
|
+
* ```js
|
|
484
|
+
* $data.updateDateMetadata({
|
|
485
|
+
* '2026-03-15': { label: '$150', availability: 'available' },
|
|
486
|
+
* })
|
|
487
|
+
* ```
|
|
488
|
+
*/
|
|
489
|
+
updateDateMetadata(provider: DateMetaProvider | undefined | null): void;
|
|
455
490
|
setView(newView: "days" | "months" | "years"): void;
|
|
456
491
|
selectMonth(targetMonth: number): void;
|
|
457
492
|
selectYear(targetYear: number): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reachweb/alpine-calendar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A lightweight, AlpineJS-native calendar component with inline/popup display, input binding with masking, and TailwindCSS 4 theming.",
|
|
6
6
|
"main": "dist/alpine-calendar.umd.js",
|
|
@@ -21,21 +21,6 @@
|
|
|
21
21
|
"sideEffects": [
|
|
22
22
|
"*.css"
|
|
23
23
|
],
|
|
24
|
-
"scripts": {
|
|
25
|
-
"dev": "vite",
|
|
26
|
-
"build": "pnpm build:lib && pnpm build:cdn && tsc --emitDeclarationOnly",
|
|
27
|
-
"build:lib": "vite build --config vite.config.lib.ts",
|
|
28
|
-
"build:cdn": "vite build --config vite.config.cdn.ts",
|
|
29
|
-
"preview": "vite preview",
|
|
30
|
-
"lint": "eslint src/",
|
|
31
|
-
"lint:fix": "eslint src/ --fix",
|
|
32
|
-
"format": "prettier --write 'src/**/*.{ts,css}'",
|
|
33
|
-
"test": "vitest run",
|
|
34
|
-
"test:watch": "vitest",
|
|
35
|
-
"test:coverage": "vitest run --coverage",
|
|
36
|
-
"typecheck": "tsc --noEmit",
|
|
37
|
-
"prepublishOnly": "pnpm run build"
|
|
38
|
-
},
|
|
39
24
|
"peerDependencies": {
|
|
40
25
|
"alpinejs": "^3.0.0"
|
|
41
26
|
},
|
|
@@ -82,5 +67,20 @@
|
|
|
82
67
|
"*.css": [
|
|
83
68
|
"prettier --write"
|
|
84
69
|
]
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"dev": "vite",
|
|
73
|
+
"build": "pnpm build:lib && pnpm build:cdn && tsc --emitDeclarationOnly",
|
|
74
|
+
"build:lib": "vite build --config vite.config.lib.ts",
|
|
75
|
+
"build:cdn": "vite build --config vite.config.cdn.ts",
|
|
76
|
+
"build:demo": "vite build --config vite.config.demo.ts",
|
|
77
|
+
"preview": "vite preview",
|
|
78
|
+
"lint": "eslint src/",
|
|
79
|
+
"lint:fix": "eslint src/ --fix",
|
|
80
|
+
"format": "prettier --write 'src/**/*.{ts,css}'",
|
|
81
|
+
"test": "vitest run",
|
|
82
|
+
"test:watch": "vitest",
|
|
83
|
+
"test:coverage": "vitest run --coverage",
|
|
84
|
+
"typecheck": "tsc --noEmit"
|
|
85
85
|
}
|
|
86
|
-
}
|
|
86
|
+
}
|