@typescript-calendar-lib/svelte 0.5.1 → 0.5.3
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 +67 -3
- package/dist/Calendar.svelte +34 -7
- package/dist/Calendar.svelte.d.ts +4 -1
- package/dist/InteractiveCalendar.svelte +11 -2
- package/dist/InteractiveCalendar.svelte.d.ts +4 -0
- package/dist/calendar.css +13 -0
- package/dist/cell-classes.d.ts +3 -0
- package/dist/cell-classes.js +2 -0
- package/dist/useCalendarState.svelte.d.ts +6 -1
- package/dist/useCalendarState.svelte.js +7 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -8,6 +8,8 @@ A `<Calendar />` Svelte 5 component with CSS-based themes and color schemes, plu
|
|
|
8
8
|
> npm install svelte @typescript-calendar-lib/svelte
|
|
9
9
|
> ```
|
|
10
10
|
|
|
11
|
+
> **Note: Build tooling** — This package ships Svelte component sources (`.svelte`), so your app must have a Svelte compiler wired up, e.g. Vite with [`@sveltejs/vite-plugin-svelte`](https://github.com/sveltejs/vite-plugin-svelte) or SvelteKit. It is not designed to be imported directly in Node.js (SSR without a compiler fails with `ERR_UNKNOWN_FILE_EXTENSION`).
|
|
12
|
+
|
|
11
13
|
## Installation
|
|
12
14
|
|
|
13
15
|
```sh
|
|
@@ -29,6 +31,33 @@ bun add @typescript-calendar-lib/svelte
|
|
|
29
31
|
<Calendar year={2026} month={9} colorScheme="ocean" theme="modern" />
|
|
30
32
|
```
|
|
31
33
|
|
|
34
|
+
## Server-side rendering
|
|
35
|
+
|
|
36
|
+
SvelteKit enables SSR for `+page.svelte` by default. Render the component normally and SvelteKit will produce the initial HTML before hydrating it in the browser:
|
|
37
|
+
|
|
38
|
+
```svelte
|
|
39
|
+
<!-- src/routes/+page.svelte -->
|
|
40
|
+
<script lang="ts">
|
|
41
|
+
import Calendar from "@typescript-calendar-lib/svelte";
|
|
42
|
+
import "@typescript-calendar-lib/svelte/calendar.css";
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<Calendar year={2026} month={9} today={new Date(2026, 8, 15)} />
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
For a standalone Svelte 5 server render, use `render` from `svelte/server`:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { render } from "svelte/server";
|
|
52
|
+
import Calendar from "@typescript-calendar-lib/svelte";
|
|
53
|
+
|
|
54
|
+
const { body, head } = render(Calendar, {
|
|
55
|
+
props: { year: 2026, month: 9, today: new Date(2026, 8, 15) },
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Run the component through a Svelte compiler such as Vite or SvelteKit; the package ships `.svelte` sources and is not a bare-Node component entry.
|
|
60
|
+
|
|
32
61
|
## Component API
|
|
33
62
|
|
|
34
63
|
### `Calendar`
|
|
@@ -47,13 +76,14 @@ bun add @typescript-calendar-lib/svelte
|
|
|
47
76
|
| `range` | `{ from: Date; to: Date }` | — | Dates to emphasize |
|
|
48
77
|
| `rangePreview` | `{ from: Date; to: Date }` | — | Candidate range preview (hover preview), rendered with the `is-in-range-preview` class |
|
|
49
78
|
| `today` | `Date` | — | Reference date for "today" styling |
|
|
50
|
-
| `selected` | `Date \| null` | — | Selected date (`.is-selected` class, `aria-pressed` in interactive mode) |
|
|
79
|
+
| `selected` | `Date \| null` | — | Selected date (`.is-selected` class, `aria-pressed="true"` in interactive mode; other buttons are `"false"`) |
|
|
51
80
|
| `cursorDate` | `Date \| null` | — | Cursor position (`.is-cursor` class) |
|
|
52
81
|
| `hoveredDate` | `Date \| null` | — | Hovered date (`.is-hovered` class) |
|
|
53
82
|
| `theme` | `ThemeName \| SvelteTheme` | `"default"` | CSS class-based theme |
|
|
54
83
|
| `colorScheme` | `ColorSchemeName \| SvelteColorScheme` | `"default"` | CSS variable-based colors |
|
|
55
84
|
| `size` | `CalendarSize` | `"md"` | Cell size |
|
|
56
85
|
| `responsive` | `boolean` | `false` | Shrink cells & padding below `480px` so the grid fits phone screens |
|
|
86
|
+
| `showWeekNumbers` | `boolean` | `false` | Render a leading week-number column (`th[scope="row"]` with class `calendar-week`); the number follows `weekStart` (`"monday"` → ISO week, `"sunday"` → week-containing-Jan-1 week) |
|
|
57
87
|
| `style` | `CSSProperties` | — | Extra styles for the root element |
|
|
58
88
|
| `interactive` | `boolean` | `false` | Enable cell click/hover/keyboard selection |
|
|
59
89
|
| `onDateClick` | `(date: Date, data?: unknown) => void` | — | Called when a day cell is clicked (or Enter/Space pressed); `data` is that cell's `cellData` value (`undefined` when none) |
|
|
@@ -103,6 +133,7 @@ Combines `useCalendarState` options, `Calendar` visual props, and event callback
|
|
|
103
133
|
| `initialMonth` | `number` | Starting month `1`–`12` (normalized if out of range) |
|
|
104
134
|
| `locale` | `Locale` | Language |
|
|
105
135
|
| `weekStart` | `WeekStart` | First day of the week |
|
|
136
|
+
| `selectionMode` | `SelectionMode` | Selection mode: `"single"` \| `"range"` (default `"single"`; range commits on the 2nd pick) |
|
|
106
137
|
| `highlight` | `Date` | Date to highlight |
|
|
107
138
|
| `range` | `{ from: Date; to: Date }` | Dates to emphasize |
|
|
108
139
|
| `today` | `Date` | Reference date for "today" styling |
|
|
@@ -119,7 +150,7 @@ Combines `useCalendarState` options, `Calendar` visual props, and event callback
|
|
|
119
150
|
|
|
120
151
|
## Interactive Mode
|
|
121
152
|
|
|
122
|
-
Set `interactive` to make day cells clickable. Each cell becomes a `<button class="calendar-day-btn">` — clickable, hoverable, and keyboard-accessible (Enter / Space). Buttons are announced with a localized `aria-label`; today gets `aria-current="date"`
|
|
153
|
+
Set `interactive` to make day cells clickable. Each cell becomes a `<button class="calendar-day-btn">` — clickable, hoverable, and keyboard-accessible (Enter / Space). Buttons are announced with a localized `aria-label` and an explicit `aria-pressed="true"` or `"false"`; today's cell gets `aria-current="date"`. The table has an `aria-label`, weekday headers use `scope="col"`, and week-number cells use `th[scope="row"]`:
|
|
123
154
|
|
|
124
155
|
```svelte
|
|
125
156
|
<Calendar
|
|
@@ -196,13 +227,46 @@ For full interactivity (cursor movement, month navigation, selection), use the `
|
|
|
196
227
|
| `moveCursor` | `(direction: Direction) => void` | Move cursor: `"up"` / `"down"` / `"left"` / `"right"` |
|
|
197
228
|
| `selectDate` | `() => void` | Select the date under the cursor |
|
|
198
229
|
| `selectDateAt` | `(date: Date) => void` | Move cursor to a date and select it (useful for mouse click) |
|
|
230
|
+
| `selectRange` | `(from: Date, to: Date) => void` | Set a committed range directly (range mode) |
|
|
199
231
|
| `setCursorToDate` | `(date: Date) => void` | Move the cursor to a specific date (no-op if outside current month) |
|
|
200
232
|
| `clearSelection` | `() => void` | Clear the selection |
|
|
201
233
|
| `cursorDate` | `Date \| null` | Date under the cursor |
|
|
202
234
|
| `selectedDate` | `Date \| null` | Currently selected date |
|
|
235
|
+
| `selectedRange` | `DateRange \| null` | Committed selection range (range mode) |
|
|
203
236
|
| `hoveredDate` | `Date \| null` | Currently hovered date |
|
|
204
237
|
| `setHoveredDate` | `(date: Date \| null) => void` | Set or clear the hovered date |
|
|
205
238
|
|
|
239
|
+
## Range selection
|
|
240
|
+
|
|
241
|
+
Pass `selectionMode="range"` to select a date range instead of a single date. Clicking alternates between **anchor → range → reset**: the 1st click sets an anchor, the 2nd commits the range, and the 3rd starts a new anchor. The committed range stays visible as the preview until the next pick begins.
|
|
242
|
+
|
|
243
|
+
```svelte
|
|
244
|
+
<InteractiveCalendar
|
|
245
|
+
initialYear={2026}
|
|
246
|
+
initialMonth={9}
|
|
247
|
+
selectionMode="range"
|
|
248
|
+
/>
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
With the raw hook, set the range explicitly via `selectRange(from, to)` and read it back from the `selectedRange` return value:
|
|
252
|
+
|
|
253
|
+
```svelte
|
|
254
|
+
<script lang="ts">
|
|
255
|
+
import { useCalendarState } from "@typescript-calendar-lib/svelte";
|
|
256
|
+
|
|
257
|
+
const cal = useCalendarState({
|
|
258
|
+
initialYear: 2026,
|
|
259
|
+
initialMonth: 9,
|
|
260
|
+
selectionMode: "range",
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
function pick() {
|
|
264
|
+
cal.selectRange(new Date(2026, 8, 1), new Date(2026, 8, 15));
|
|
265
|
+
console.log(cal.selectedRange); // { from, to } | null
|
|
266
|
+
}
|
|
267
|
+
</script>
|
|
268
|
+
```
|
|
269
|
+
|
|
206
270
|
## Themes
|
|
207
271
|
|
|
208
272
|
### `ThemeName`
|
|
@@ -334,7 +398,7 @@ It's **off by default** to keep existing layouts unchanged. The calendar root ge
|
|
|
334
398
|
|
|
335
399
|
## Cell Classes
|
|
336
400
|
|
|
337
|
-
Each day cell gets semantic classes you can target with CSS
|
|
401
|
+
Each day cell gets semantic classes you can target with CSS. The table has an `aria-label`, weekday headers use `scope="col"`, week-number cells use `th[scope="row"]`, today's cell uses `aria-current="date"`, and interactive day buttons expose `aria-pressed="true"` or `"false"`:
|
|
338
402
|
|
|
339
403
|
| Class | When |
|
|
340
404
|
| :--- | :--- |
|
package/dist/Calendar.svelte
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { CalendarCellState, CalendarOptions } from "@typescript-calendar-lib/core";
|
|
3
3
|
import {
|
|
4
|
+
addDays,
|
|
4
5
|
buildMonthGrid,
|
|
5
6
|
createDate,
|
|
6
7
|
getCalendarCellState,
|
|
8
|
+
getISOWeek,
|
|
7
9
|
getMonthName,
|
|
10
|
+
getWeekOfYear,
|
|
8
11
|
getWeekdayHeaders,
|
|
9
12
|
isSameDay,
|
|
10
13
|
} from "@typescript-calendar-lib/core";
|
|
@@ -26,6 +29,7 @@
|
|
|
26
29
|
year: number;
|
|
27
30
|
month: number;
|
|
28
31
|
locale?: CalendarOptions["locale"];
|
|
32
|
+
holidayLocale?: CalendarOptions["holidayLocale"];
|
|
29
33
|
weekStart?: CalendarOptions["weekStart"];
|
|
30
34
|
highlight?: Date;
|
|
31
35
|
/** 範囲強調 */
|
|
@@ -34,7 +38,7 @@
|
|
|
34
38
|
rangePreview?: { from: Date; to: Date };
|
|
35
39
|
/** 今日の基準日。カラースキームの today 着色に使用 */
|
|
36
40
|
today?: Date;
|
|
37
|
-
/** 選択済み日付。該当セルに is-selected
|
|
41
|
+
/** 選択済み日付。該当セルに is-selected クラスが付き、interactive 時は button に aria-pressed が付く */
|
|
38
42
|
selected?: Date | null;
|
|
39
43
|
/** カーソル位置の日付。該当セルに is-cursor クラスが付く */
|
|
40
44
|
cursorDate?: Date | null;
|
|
@@ -48,6 +52,8 @@
|
|
|
48
52
|
size?: CalendarSize;
|
|
49
53
|
/** 狭い画面(スマホ等)でセルサイズと余白を自動調整する。既定は false(無効) */
|
|
50
54
|
responsive?: boolean;
|
|
55
|
+
/** 行の先頭に週番号を表示する。既定は false(非表示) */
|
|
56
|
+
showWeekNumbers?: boolean;
|
|
51
57
|
/** root 要素に追加するスタイル。CSS変数(--cal-*)で自由に上書きできる */
|
|
52
58
|
style?: CSSProperties;
|
|
53
59
|
|
|
@@ -83,6 +89,7 @@
|
|
|
83
89
|
year,
|
|
84
90
|
month,
|
|
85
91
|
locale = "en",
|
|
92
|
+
holidayLocale,
|
|
86
93
|
weekStart = "sunday",
|
|
87
94
|
highlight,
|
|
88
95
|
range,
|
|
@@ -95,6 +102,7 @@
|
|
|
95
102
|
colorScheme = "default",
|
|
96
103
|
size = "md",
|
|
97
104
|
responsive = false,
|
|
105
|
+
showWeekNumbers = false,
|
|
98
106
|
style,
|
|
99
107
|
interactive = false,
|
|
100
108
|
onDateClick,
|
|
@@ -108,10 +116,11 @@
|
|
|
108
116
|
|
|
109
117
|
const cellDate = (day: number): Date => createDate(year, month - 1, day);
|
|
110
118
|
const cellState = (day: number): CalendarCellState =>
|
|
111
|
-
getCalendarCellState(cellDate(day), { today, highlight, range, isDateDisabled });
|
|
119
|
+
getCalendarCellState(cellDate(day), { today, holidayLocale, highlight, range, isDateDisabled });
|
|
112
120
|
const cellClass = (day: number): string | undefined =>
|
|
113
121
|
getCellClasses(cellDate(day), {
|
|
114
122
|
today,
|
|
123
|
+
holidayLocale,
|
|
115
124
|
highlight,
|
|
116
125
|
range,
|
|
117
126
|
rangePreview,
|
|
@@ -127,6 +136,15 @@
|
|
|
127
136
|
today != null && isSameDay(cellDate(day), today);
|
|
128
137
|
const isCursorDay = (day: number): boolean =>
|
|
129
138
|
cursorDate != null && isSameDay(cellDate(day), cursorDate);
|
|
139
|
+
const weekOf = (row: (number | null)[]): number | null => {
|
|
140
|
+
const firstIdx = row.findIndex((d) => d !== null);
|
|
141
|
+
if (firstIdx === -1) return null;
|
|
142
|
+
const firstDate = createDate(year, month - 1, row[firstIdx]!);
|
|
143
|
+
const weekStartDate = addDays(firstDate, -firstIdx);
|
|
144
|
+
return weekStart === "monday"
|
|
145
|
+
? getISOWeek(weekStartDate)
|
|
146
|
+
: getWeekOfYear(weekStartDate);
|
|
147
|
+
};
|
|
130
148
|
const handleCellClick = (day: number) => {
|
|
131
149
|
if (interactive && onDateClick) {
|
|
132
150
|
const date = cellDate(day);
|
|
@@ -160,11 +178,14 @@
|
|
|
160
178
|
<div class="calendar-header">
|
|
161
179
|
<h2>{getMonthName(locale, month)} {year}</h2>
|
|
162
180
|
</div>
|
|
163
|
-
<table>
|
|
181
|
+
<table aria-label={`${getMonthName(locale, month)} ${year}`}>
|
|
164
182
|
<thead>
|
|
165
183
|
<tr>
|
|
184
|
+
{#if showWeekNumbers}
|
|
185
|
+
<th class="calendar-week" scope="col" aria-label="Week number"></th>
|
|
186
|
+
{/if}
|
|
166
187
|
{#each getWeekdayHeaders(locale, weekStart) as day (day)}
|
|
167
|
-
<th>{day}</th>
|
|
188
|
+
<th scope="col">{day}</th>
|
|
168
189
|
{/each}
|
|
169
190
|
</tr>
|
|
170
191
|
</thead>
|
|
@@ -172,11 +193,18 @@
|
|
|
172
193
|
{#each buildMonthGrid(year, month, weekStart) as row, i (i)}
|
|
173
194
|
{#if !row.every((d) => d === null)}
|
|
174
195
|
<tr>
|
|
196
|
+
{#if showWeekNumbers}
|
|
197
|
+
<th class="calendar-week" scope="row">{weekOf(row)}</th>
|
|
198
|
+
{/if}
|
|
175
199
|
{#each row as day, j (j)}
|
|
176
200
|
{#if day === null}
|
|
177
201
|
<td></td>
|
|
178
202
|
{:else}
|
|
179
|
-
<td
|
|
203
|
+
<td
|
|
204
|
+
class={cellClass(day)}
|
|
205
|
+
aria-current={isTodayDay(day) ? "date" : undefined}
|
|
206
|
+
aria-disabled={isDisabledDay(day) || undefined}
|
|
207
|
+
>
|
|
180
208
|
{#if interactive}
|
|
181
209
|
<button
|
|
182
210
|
type="button"
|
|
@@ -186,8 +214,7 @@
|
|
|
186
214
|
tabindex={isCursorDay(day) ? 0 : -1}
|
|
187
215
|
data-cursor={isCursorDay(day) ? "true" : undefined}
|
|
188
216
|
aria-label={formatCellLabel(locale, year, month, day)}
|
|
189
|
-
aria-pressed={isSelectedDay(day)
|
|
190
|
-
aria-current={isTodayDay(day) ? "date" : undefined}
|
|
217
|
+
aria-pressed={isSelectedDay(day)}
|
|
191
218
|
disabled={isDisabledDay(day)}
|
|
192
219
|
>
|
|
193
220
|
{#if renderCell}
|
|
@@ -6,6 +6,7 @@ interface CalendarProps {
|
|
|
6
6
|
year: number;
|
|
7
7
|
month: number;
|
|
8
8
|
locale?: CalendarOptions["locale"];
|
|
9
|
+
holidayLocale?: CalendarOptions["holidayLocale"];
|
|
9
10
|
weekStart?: CalendarOptions["weekStart"];
|
|
10
11
|
highlight?: Date;
|
|
11
12
|
/** 範囲強調 */
|
|
@@ -20,7 +21,7 @@ interface CalendarProps {
|
|
|
20
21
|
};
|
|
21
22
|
/** 今日の基準日。カラースキームの today 着色に使用 */
|
|
22
23
|
today?: Date;
|
|
23
|
-
/** 選択済み日付。該当セルに is-selected
|
|
24
|
+
/** 選択済み日付。該当セルに is-selected クラスが付き、interactive 時は button に aria-pressed が付く */
|
|
24
25
|
selected?: Date | null;
|
|
25
26
|
/** カーソル位置の日付。該当セルに is-cursor クラスが付く */
|
|
26
27
|
cursorDate?: Date | null;
|
|
@@ -34,6 +35,8 @@ interface CalendarProps {
|
|
|
34
35
|
size?: CalendarSize;
|
|
35
36
|
/** 狭い画面(スマホ等)でセルサイズと余白を自動調整する。既定は false(無効) */
|
|
36
37
|
responsive?: boolean;
|
|
38
|
+
/** 行の先頭に週番号を表示する。既定は false(非表示) */
|
|
39
|
+
showWeekNumbers?: boolean;
|
|
37
40
|
/** root 要素に追加するスタイル。CSS変数(--cal-*)で自由に上書きできる */
|
|
38
41
|
style?: CSSProperties;
|
|
39
42
|
/** インタラクティブモードを有効にする。セルクリック・ホバー・キーボード選択が可能になる */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { CalendarCellState, CalendarOptions } from "@typescript-calendar-lib/core";
|
|
3
|
+
import type { SelectionMode } from "@typescript-calendar-lib/tui";
|
|
3
4
|
import { keyToAction } from "@typescript-calendar-lib/tui";
|
|
4
5
|
import Calendar from "./Calendar.svelte";
|
|
5
6
|
import { buildRangePreview } from "./range-preview.js";
|
|
@@ -21,11 +22,14 @@
|
|
|
21
22
|
/** 表示開始月 (1-12)。範囲外は正規化される */
|
|
22
23
|
initialMonth?: number;
|
|
23
24
|
locale?: CalendarOptions["locale"];
|
|
25
|
+
holidayLocale?: CalendarOptions["holidayLocale"];
|
|
24
26
|
weekStart?: CalendarOptions["weekStart"];
|
|
25
27
|
/** ハイライト対象日 */
|
|
26
28
|
highlight?: Date;
|
|
27
29
|
/** 色付け範囲 */
|
|
28
30
|
range?: { from: Date; to: Date };
|
|
31
|
+
/** 選択方式。既定は "single"。range では 2 回のクリックで範囲が確定する */
|
|
32
|
+
selectionMode?: SelectionMode;
|
|
29
33
|
/** 今日の基準日。省略時は初回レンダリング時刻に解決される */
|
|
30
34
|
today?: Date;
|
|
31
35
|
/** 選択不可日付の判定。true を返した日付は選択・カーソル移動・ホバーの対象外になる */
|
|
@@ -63,9 +67,11 @@
|
|
|
63
67
|
initialYear,
|
|
64
68
|
initialMonth,
|
|
65
69
|
locale,
|
|
70
|
+
holidayLocale,
|
|
66
71
|
weekStart,
|
|
67
72
|
highlight,
|
|
68
73
|
range,
|
|
74
|
+
selectionMode,
|
|
69
75
|
today,
|
|
70
76
|
isDateDisabled,
|
|
71
77
|
theme,
|
|
@@ -84,11 +90,13 @@
|
|
|
84
90
|
initialYear,
|
|
85
91
|
initialMonth,
|
|
86
92
|
locale,
|
|
93
|
+
holidayLocale,
|
|
87
94
|
weekStart,
|
|
88
95
|
today,
|
|
89
96
|
highlight,
|
|
90
97
|
range,
|
|
91
98
|
isDateDisabled,
|
|
99
|
+
selectionMode,
|
|
92
100
|
}));
|
|
93
101
|
|
|
94
102
|
// クリック(マウス・Enter/Space 共通)で日付を選択する。
|
|
@@ -108,9 +116,9 @@
|
|
|
108
116
|
onDateLeave?.();
|
|
109
117
|
};
|
|
110
118
|
|
|
111
|
-
//
|
|
119
|
+
// 確定した選択範囲があればそれを、なければ選択日〜ホバー日のプレビューを表示する
|
|
112
120
|
const rangePreview = $derived(
|
|
113
|
-
buildRangePreview(cal.selectedDate, cal.hoveredDate),
|
|
121
|
+
cal.selectedRange ?? buildRangePreview(cal.selectedDate, cal.hoveredDate),
|
|
114
122
|
);
|
|
115
123
|
|
|
116
124
|
// カーソルが動いたときだけ、そのセルへフォーカスを移す(初回マウントでは動かさない)
|
|
@@ -147,6 +155,7 @@
|
|
|
147
155
|
year={cal.state.year}
|
|
148
156
|
month={cal.state.month}
|
|
149
157
|
locale={cal.state.options.locale}
|
|
158
|
+
holidayLocale={cal.state.options.holidayLocale}
|
|
150
159
|
weekStart={cal.state.options.weekStart}
|
|
151
160
|
highlight={cal.state.options.highlight}
|
|
152
161
|
range={cal.state.options.range}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CalendarCellState, CalendarOptions } from "@typescript-calendar-lib/core";
|
|
2
|
+
import type { SelectionMode } from "@typescript-calendar-lib/tui";
|
|
2
3
|
import type { CalendarSize } from "./size.js";
|
|
3
4
|
import type { CSSProperties } from "./style.js";
|
|
4
5
|
import type { ColorSchemeName, SvelteColorScheme, SvelteTheme, ThemeName } from "./themes.js";
|
|
@@ -8,6 +9,7 @@ interface InteractiveCalendarProps {
|
|
|
8
9
|
/** 表示開始月 (1-12)。範囲外は正規化される */
|
|
9
10
|
initialMonth?: number;
|
|
10
11
|
locale?: CalendarOptions["locale"];
|
|
12
|
+
holidayLocale?: CalendarOptions["holidayLocale"];
|
|
11
13
|
weekStart?: CalendarOptions["weekStart"];
|
|
12
14
|
/** ハイライト対象日 */
|
|
13
15
|
highlight?: Date;
|
|
@@ -16,6 +18,8 @@ interface InteractiveCalendarProps {
|
|
|
16
18
|
from: Date;
|
|
17
19
|
to: Date;
|
|
18
20
|
};
|
|
21
|
+
/** 選択方式。既定は "single"。range では 2 回のクリックで範囲が確定する */
|
|
22
|
+
selectionMode?: SelectionMode;
|
|
19
23
|
/** 今日の基準日。省略時は初回レンダリング時刻に解決される */
|
|
20
24
|
today?: Date;
|
|
21
25
|
/** 選択不可日付の判定。true を返した日付は選択・カーソル移動・ホバーの対象外になる */
|
package/dist/calendar.css
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
--cal-fg: #1e293b;
|
|
4
4
|
--cal-accent: #dc2626;
|
|
5
5
|
--cal-weekend-fg: #94a3b8;
|
|
6
|
+
--cal-holiday-fg: #d33;
|
|
6
7
|
--cal-border: #e2e8f0;
|
|
7
8
|
--cal-header-bg: #f8fafc;
|
|
8
9
|
--cal-highlight-bg: #dc2626;
|
|
@@ -43,6 +44,14 @@
|
|
|
43
44
|
font-weight: 600;
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
.calendar th.calendar-week, .calendar td.calendar-week {
|
|
48
|
+
width: calc(var(--cal-cell-w) * .6);
|
|
49
|
+
min-width: 1.25rem;
|
|
50
|
+
color: var(--cal-weekend-fg);
|
|
51
|
+
font-size: .75rem;
|
|
52
|
+
font-weight: 400;
|
|
53
|
+
}
|
|
54
|
+
|
|
46
55
|
.calendar .calendar-header {
|
|
47
56
|
text-align: center;
|
|
48
57
|
margin-bottom: .5rem;
|
|
@@ -60,6 +69,10 @@
|
|
|
60
69
|
color: var(--cal-weekend-fg);
|
|
61
70
|
}
|
|
62
71
|
|
|
72
|
+
.calendar td.is-holiday {
|
|
73
|
+
color: var(--cal-holiday-fg, #d33);
|
|
74
|
+
}
|
|
75
|
+
|
|
63
76
|
.calendar td.is-disabled {
|
|
64
77
|
color: var(--cal-disabled-fg, var(--cal-weekend-fg));
|
|
65
78
|
opacity: .5;
|
package/dist/cell-classes.d.ts
CHANGED
package/dist/cell-classes.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { DateRange } from "@typescript-calendar-lib/core";
|
|
1
2
|
import type { CalendarState, CalendarStateOptions, Direction, MonthDirection } from "@typescript-calendar-lib/tui";
|
|
2
|
-
export interface UseCalendarStateOptions extends Pick<CalendarStateOptions, "locale" | "weekStart" | "today" | "highlight" | "range" | "isDateDisabled"> {
|
|
3
|
+
export interface UseCalendarStateOptions extends Pick<CalendarStateOptions, "locale" | "holidayLocale" | "weekStart" | "today" | "highlight" | "range" | "isDateDisabled" | "selectionMode"> {
|
|
3
4
|
initialYear?: number;
|
|
4
5
|
initialMonth?: number;
|
|
5
6
|
}
|
|
@@ -27,12 +28,16 @@ export interface UseCalendarStateReturn {
|
|
|
27
28
|
setCursorToDate: (date: Date) => void;
|
|
28
29
|
/** 指定した日付を選択し、カーソルもそこへ移動する(当月に無ければ何もしない) */
|
|
29
30
|
selectDateAt: (date: Date) => void;
|
|
31
|
+
/** from/to の範囲を選択範囲として直接設定する(順序は自動で整列される) */
|
|
32
|
+
selectRange: (from: Date, to: Date) => void;
|
|
30
33
|
/** 選択を解除 */
|
|
31
34
|
clearSelection: () => void;
|
|
32
35
|
/** カーソル位置の日付(null の場合あり) */
|
|
33
36
|
cursorDate: Date | null;
|
|
34
37
|
/** 選択済み日付(null の場合あり) */
|
|
35
38
|
selectedDate: Date | null;
|
|
39
|
+
/** 確定した選択範囲(未確定・single モードでは null) */
|
|
40
|
+
selectedRange: DateRange | null;
|
|
36
41
|
/** ホバー中の日付(null の場合あり) */
|
|
37
42
|
hoveredDate: Date | null;
|
|
38
43
|
/** ホバー日付を更新する */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { clearSelection, createCalendarState, getCursorDate, getSelectedDate, goToToday, moveCursor, navigateMonth, sameStateOptions, selectDate, selectDateAt, setCursorToDate, updateStateOptions, } from "@typescript-calendar-lib/tui";
|
|
1
|
+
import { clearSelection, createCalendarState, getCursorDate, getSelectedDate, getSelectedRange, goToToday, moveCursor, navigateMonth, sameStateOptions, selectDate, selectDateAt, selectRange, setCursorToDate, updateStateOptions, } from "@typescript-calendar-lib/tui";
|
|
2
2
|
/** undefined を含む日付を値(時刻)で比較する */
|
|
3
3
|
/**
|
|
4
4
|
* tui の不変状態機械を包む Svelte 5 (runes) のリアクティブ状態。
|
|
@@ -69,6 +69,9 @@ export function useCalendarState(options = {}) {
|
|
|
69
69
|
get selectedDate() {
|
|
70
70
|
return getSelectedDate(state);
|
|
71
71
|
},
|
|
72
|
+
get selectedRange() {
|
|
73
|
+
return getSelectedRange(state);
|
|
74
|
+
},
|
|
72
75
|
get hoveredDate() {
|
|
73
76
|
return hoveredDate;
|
|
74
77
|
},
|
|
@@ -93,6 +96,9 @@ export function useCalendarState(options = {}) {
|
|
|
93
96
|
selectDateAt: (date) => {
|
|
94
97
|
state = selectDateAt(state, date);
|
|
95
98
|
},
|
|
99
|
+
selectRange: (from, to) => {
|
|
100
|
+
state = selectRange(state, from, to);
|
|
101
|
+
},
|
|
96
102
|
clearSelection: () => {
|
|
97
103
|
state = clearSelection(state);
|
|
98
104
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typescript-calendar-lib/svelte",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "Svelte 5 components and reactive state for typescript-calendar-lib",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"svelte": "^5"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@typescript-calendar-lib/core": "0.5.
|
|
38
|
-
"@typescript-calendar-lib/tui": "0.5.
|
|
39
|
-
"@typescript-calendar-lib/web": "0.5.
|
|
37
|
+
"@typescript-calendar-lib/core": "^0.5.3",
|
|
38
|
+
"@typescript-calendar-lib/tui": "^0.5.3",
|
|
39
|
+
"@typescript-calendar-lib/web": "^0.5.3"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@sveltejs/package": "^2.5.8",
|