@typescript-calendar-lib/svelte 0.5.3 → 0.6.1
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 +48 -5
- package/dist/Calendar.svelte +137 -46
- package/dist/Calendar.svelte.d.ts +6 -2
- package/dist/InteractiveCalendar.svelte +36 -3
- package/dist/InteractiveCalendar.svelte.d.ts +11 -2
- package/dist/calendar.css +64 -8
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/themes.d.ts +2 -2
- package/dist/themes.js +1 -1
- package/dist/useCalendarState.svelte.d.ts +15 -0
- package/dist/useCalendarState.svelte.js +35 -5
- package/package.json +16 -5
- package/dist/cell-classes.d.ts +0 -26
- package/dist/cell-classes.js +0 -29
package/README.md
CHANGED
|
@@ -71,10 +71,12 @@ Run the component through a Svelte compiler such as Vite or SvelteKit; the packa
|
|
|
71
71
|
| `year` | `number` | — (required) | Calendar year |
|
|
72
72
|
| `month` | `number` | — (required) | Month, 1-indexed (`1`–`12`) |
|
|
73
73
|
| `locale` | `"en" \| "ja" \| "es" \| "de" \| "fr" \| "ko" \| "zh"` | `"en"` | Language |
|
|
74
|
+
| `holidayLocale` | `"en" \| "ja" \| "es" \| "de" \| "fr" \| "ko" \| "zh"` | `"ja"` | Holiday rules (fixed-date holidays for every locale; moving holidays such as Easter are not included) |
|
|
74
75
|
| `weekStart` | `"sunday" \| "monday"` | `"sunday"` | First day of the week |
|
|
75
76
|
| `highlight` | `Date` | — | Date to highlight |
|
|
76
77
|
| `range` | `{ from: Date; to: Date }` | — | Dates to emphasize |
|
|
77
78
|
| `rangePreview` | `{ from: Date; to: Date }` | — | Candidate range preview (hover preview), rendered with the `is-in-range-preview` class |
|
|
79
|
+
| `isDateDisabled` | `(date: Date) => boolean` | — | Mark dates as non-selectable in interactive mode (`is-disabled` class) |
|
|
78
80
|
| `today` | `Date` | — | Reference date for "today" styling |
|
|
79
81
|
| `selected` | `Date \| null` | — | Selected date (`.is-selected` class, `aria-pressed="true"` in interactive mode; other buttons are `"false"`) |
|
|
80
82
|
| `cursorDate` | `Date \| null` | — | Cursor position (`.is-cursor` class) |
|
|
@@ -89,6 +91,7 @@ Run the component through a Svelte compiler such as Vite or SvelteKit; the packa
|
|
|
89
91
|
| `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) |
|
|
90
92
|
| `onDateHover` | `(date: Date) => void` | — | Called when a day cell is hovered |
|
|
91
93
|
| `onDateLeave` | `() => void` | — | Called when the mouse leaves the calendar |
|
|
94
|
+
| `onkeydown` | `(event: KeyboardEvent) => void` | — | Keyboard handler fired on the root element (arrow keys etc.) |
|
|
92
95
|
| `cellData` | `(date: Date) => unknown` | — | Resolve per-cell data; passed to `renderCell` and `onDateClick` |
|
|
93
96
|
| `renderCell` | `(day, date, state, data?) => string` | — | Custom cell content; the returned string is inserted as plain text (XSS-safe) |
|
|
94
97
|
|
|
@@ -123,6 +126,18 @@ A turnkey component that wires `useCalendarState` and `Calendar` together with b
|
|
|
123
126
|
- **Arrow keys** — moves the cursor with focus tracking
|
|
124
127
|
- **PageUp/PageDown** — navigates to the previous/next month
|
|
125
128
|
|
|
129
|
+
### Disabled Dates
|
|
130
|
+
|
|
131
|
+
Pass `isDateDisabled` to mark dates as non-selectable. Disabled cells get the `is-disabled` class, cannot receive keyboard focus or be clicked, and `Arrow*` navigation skips over them:
|
|
132
|
+
|
|
133
|
+
```svelte
|
|
134
|
+
<InteractiveCalendar
|
|
135
|
+
initialYear={2026}
|
|
136
|
+
initialMonth={9}
|
|
137
|
+
isDateDisabled={(date) => date.getDay() === 0} // disable Sundays
|
|
138
|
+
/>
|
|
139
|
+
```
|
|
140
|
+
|
|
126
141
|
### Props
|
|
127
142
|
|
|
128
143
|
Combines `useCalendarState` options, `Calendar` visual props, and event callbacks:
|
|
@@ -132,25 +147,39 @@ Combines `useCalendarState` options, `Calendar` visual props, and event callback
|
|
|
132
147
|
| `initialYear` | `number` | Starting year (defaults to today's year) |
|
|
133
148
|
| `initialMonth` | `number` | Starting month `1`–`12` (normalized if out of range) |
|
|
134
149
|
| `locale` | `Locale` | Language |
|
|
150
|
+
| `holidayLocale` | `Locale` | Locale used for holiday detection (defaults to `ja`) |
|
|
135
151
|
| `weekStart` | `WeekStart` | First day of the week |
|
|
152
|
+
| `showWeekNumbers` | `boolean` | Render the leading week-number column |
|
|
136
153
|
| `selectionMode` | `SelectionMode` | Selection mode: `"single"` \| `"range"` (default `"single"`; range commits on the 2nd pick) |
|
|
137
154
|
| `highlight` | `Date` | Date to highlight |
|
|
138
155
|
| `range` | `{ from: Date; to: Date }` | Dates to emphasize |
|
|
139
156
|
| `today` | `Date` | Reference date for "today" styling |
|
|
157
|
+
| `isDateDisabled` | `(date: Date) => boolean` | Mark dates as non-selectable |
|
|
158
|
+
| `onkeydown` | `(event: KeyboardEvent) => void` | Keyboard handler fired on the root element (arrow keys etc.) |
|
|
159
|
+
| `onMonthChange` | `(year: number, month: number) => void` | Called when the displayed month changes |
|
|
140
160
|
| `theme` | `ThemeName \| SvelteTheme` | CSS class-based theme |
|
|
141
161
|
| `colorScheme` | `ColorSchemeName \| SvelteColorScheme` | CSS variable-based colors |
|
|
142
162
|
| `size` | `CalendarSize` | Cell size |
|
|
143
163
|
| `responsive` | `boolean` | Shrink cells & padding below `480px` so the grid fits phone screens |
|
|
144
164
|
| `style` | `CSSProperties` | Extra styles for the root element |
|
|
145
165
|
| `cellData` | `(date: Date) => unknown` | Resolve per-cell data; passed to `renderCell` and `onDateClick` |
|
|
146
|
-
| `renderCell` | `(day, date, state, data?) => string` | Custom cell content (plain text
|
|
166
|
+
| `renderCell` | `(day, date, state, data?) => string \| Snippet` | Custom cell content (plain text is XSS-safe; a `Snippet` renders markup) |
|
|
147
167
|
| `onDateClick` | `(date: Date, data?: unknown) => void` | Called when a date is selected; `data` is the cell's `cellData` value |
|
|
148
168
|
| `onDateHover` | `(date: Date) => void` | Called on cell hover |
|
|
149
169
|
| `onDateLeave` | `() => void` | Called when the mouse leaves the calendar |
|
|
150
170
|
|
|
171
|
+
## Accessibility notes
|
|
172
|
+
|
|
173
|
+
- The `<table>` is labelled by the visible `<h2>` heading through `aria-labelledby`, so screen readers announce the same month text you see - exactly once, instead of a duplicated `aria-label`.
|
|
174
|
+
- In interactive mode the heading itself is the live region (`aria-live="polite"` + `aria-atomic="true"`), so navigating to another month is announced (WAI-ARIA APG Date Picker Dialog). The month name is **not** copied into a separate hidden element, which would put it into the accessibility tree twice.
|
|
175
|
+
- In interactive mode the table becomes `role="grid"` with `role="gridcell"` cells; the non-interactive table keeps native table semantics.
|
|
176
|
+
- Padding cells carry the `is-blank` class instead of relying on `td:empty`, so grid lines do not break when a renderer emits stray whitespace or comments inside a cell.
|
|
177
|
+
- Heading `id` values are allocated per component instance, so several calendars of the same month can coexist on one page without duplicate ids.
|
|
178
|
+
- All colour schemes keep text at 4.5:1 or better against its background; grid borders target 2:1 (decorative), and `prefers-reduced-motion` / `forced-colors` are honoured.
|
|
179
|
+
|
|
151
180
|
## Interactive Mode
|
|
152
181
|
|
|
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
|
|
182
|
+
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 is labelled by the visible `<h2>` heading via `aria-labelledby`, weekday headers use `scope="col"`, and week-number cells use `th[scope="row"]`. In interactive mode it is exposed as a `role="grid"` table with `role="gridcell"` cells (WAI-ARIA APG calendar pattern), today's cell gets `aria-current="date"`, the selected date gets `aria-selected`, and only the cursor cell is tabbable (roving tabindex):
|
|
154
183
|
|
|
155
184
|
```svelte
|
|
156
185
|
<Calendar
|
|
@@ -224,6 +253,9 @@ For full interactivity (cursor movement, month navigation, selection), use the `
|
|
|
224
253
|
| `goNext` | `() => void` | Move to next month |
|
|
225
254
|
| `goPrev` | `() => void` | Move to previous month |
|
|
226
255
|
| `goToday` | `() => void` | Jump to today's month |
|
|
256
|
+
| `navigateYear` | `(direction: MonthDirection) => void` | Move to the previous/next year (`"prev"` / `"next"`) |
|
|
257
|
+
| `goToMonth` | `(year: number, month: number) => void` | Jump to a specific year and month |
|
|
258
|
+
| `goToDate` | `(date: Date) => void` | Jump to a date's month and put the cursor on that date |
|
|
227
259
|
| `moveCursor` | `(direction: Direction) => void` | Move cursor: `"up"` / `"down"` / `"left"` / `"right"` |
|
|
228
260
|
| `selectDate` | `() => void` | Select the date under the cursor |
|
|
229
261
|
| `selectDateAt` | `(date: Date) => void` | Move cursor to a date and select it (useful for mouse click) |
|
|
@@ -327,6 +359,7 @@ Available variables:
|
|
|
327
359
|
| `--cal-fg` | Foreground |
|
|
328
360
|
| `--cal-accent` | Accent (highlight) |
|
|
329
361
|
| `--cal-weekend-fg` | Weekend foreground |
|
|
362
|
+
| `--cal-holiday-fg` | Holiday foreground |
|
|
330
363
|
| `--cal-border` | Borders |
|
|
331
364
|
| `--cal-header-bg` | Header background |
|
|
332
365
|
| `--cal-highlight-bg` | Highlight background |
|
|
@@ -335,8 +368,11 @@ Available variables:
|
|
|
335
368
|
| `--cal-range-preview-bg` | Range preview background (falls back to `--cal-range-bg`) |
|
|
336
369
|
| `--cal-today-bg` | Today background |
|
|
337
370
|
| `--cal-today-fg` | Today foreground |
|
|
338
|
-
| `--cal-selected-bg` | Selected background |
|
|
339
|
-
| `--cal-selected-fg` | Selected foreground |
|
|
371
|
+
| `--cal-selected-bg` | Selected cell background (interactive mode) |
|
|
372
|
+
| `--cal-selected-fg` | Selected cell foreground (interactive mode) |
|
|
373
|
+
| `--cal-disabled-fg` | Disabled cell foreground (interactive mode) |
|
|
374
|
+
|
|
375
|
+
`calendar.css` also uses a CSS-only `--cal-hover-bg` (falls back to `--cal-range-bg`) for the interactive hover state; set it with `style` or your own CSS.
|
|
340
376
|
|
|
341
377
|
Pass a custom scheme directly:
|
|
342
378
|
|
|
@@ -398,16 +434,18 @@ It's **off by default** to keep existing layouts unchanged. The calendar root ge
|
|
|
398
434
|
|
|
399
435
|
## Cell Classes
|
|
400
436
|
|
|
401
|
-
Each day cell gets semantic classes you can target with CSS. The table
|
|
437
|
+
Each day cell gets semantic classes you can target with CSS. The table is labelled by the visible `<h2>` heading via `aria-labelledby`, 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"`:
|
|
402
438
|
|
|
403
439
|
| Class | When |
|
|
404
440
|
| :--- | :--- |
|
|
405
441
|
| `is-weekend` | Saturday or Sunday |
|
|
442
|
+
| `is-holiday` | Holiday per `holidayLocale` (default `"ja"`) |
|
|
406
443
|
| `is-today` | Matches `today` |
|
|
407
444
|
| `is-highlight` | Matches `highlight` |
|
|
408
445
|
| `is-in-range` | Inside `range` |
|
|
409
446
|
| `is-in-range-preview` | Inside `rangePreview` |
|
|
410
447
|
| `is-hovered` | Matches `hoveredDate` (interactive mode) |
|
|
448
|
+
| `is-disabled` | Date returned `true` from `isDateDisabled` (interactive mode) |
|
|
411
449
|
| `is-selected` | Matches `selected` |
|
|
412
450
|
| `is-cursor` | Matches `cursorDate` |
|
|
413
451
|
|
|
@@ -419,9 +457,13 @@ import Calendar, {
|
|
|
419
457
|
buildRangePreview,
|
|
420
458
|
buildSizeStyle,
|
|
421
459
|
COLOR_SCHEMES,
|
|
460
|
+
getBlankClasses,
|
|
422
461
|
getCellClasses,
|
|
462
|
+
getCellStateClasses,
|
|
463
|
+
getSelectionCellClasses,
|
|
423
464
|
InteractiveCalendar,
|
|
424
465
|
isSizeName,
|
|
466
|
+
joinCellClassLists,
|
|
425
467
|
resolveColorScheme,
|
|
426
468
|
resolveTheme,
|
|
427
469
|
THEMES,
|
|
@@ -435,6 +477,7 @@ import type {
|
|
|
435
477
|
CellStateOptions,
|
|
436
478
|
ColorSchemeName,
|
|
437
479
|
CSSProperties,
|
|
480
|
+
SelectionCellOptions,
|
|
438
481
|
SvelteColorScheme,
|
|
439
482
|
SvelteTheme,
|
|
440
483
|
ThemeName,
|
package/dist/Calendar.svelte
CHANGED
|
@@ -11,8 +11,14 @@
|
|
|
11
11
|
getWeekdayHeaders,
|
|
12
12
|
isSameDay,
|
|
13
13
|
} from "@typescript-calendar-lib/core";
|
|
14
|
-
import {
|
|
15
|
-
|
|
14
|
+
import {
|
|
15
|
+
formatCellLabel,
|
|
16
|
+
getBlankClasses,
|
|
17
|
+
getCellStateClasses,
|
|
18
|
+
getSelectionCellClasses,
|
|
19
|
+
joinCellClassLists,
|
|
20
|
+
uiString,
|
|
21
|
+
} from "@typescript-calendar-lib/web";
|
|
16
22
|
import type { CalendarSize } from "./size.js";
|
|
17
23
|
import { buildSizeStyle, isSizeName } from "./size.js";
|
|
18
24
|
import type { CSSProperties } from "./style.js";
|
|
@@ -23,7 +29,8 @@
|
|
|
23
29
|
SvelteTheme,
|
|
24
30
|
ThemeName,
|
|
25
31
|
} from "./themes.js";
|
|
26
|
-
import {
|
|
32
|
+
import type { Snippet } from "svelte";
|
|
33
|
+
import { mergeColorScheme, resolveTheme } from "./themes.js";
|
|
27
34
|
|
|
28
35
|
interface CalendarProps {
|
|
29
36
|
year: number;
|
|
@@ -72,13 +79,16 @@
|
|
|
72
79
|
|
|
73
80
|
// ── セル状態 ──
|
|
74
81
|
|
|
75
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* セル内容のカスタムレンダリング。interactive 時は button の子として描画される。
|
|
84
|
+
* Snippet(markup)または文字列のどちらでも受け付ける。第4引数に該当日のデータが渡る。
|
|
85
|
+
*/
|
|
76
86
|
renderCell?: (
|
|
77
87
|
day: number,
|
|
78
88
|
date: Date,
|
|
79
89
|
state: CalendarCellState,
|
|
80
90
|
data?: unknown,
|
|
81
|
-
) => string;
|
|
91
|
+
) => string | Snippet;
|
|
82
92
|
/** 各セルに付与するユーザー定義データを解決する関数。実セルのみに呼ばれる */
|
|
83
93
|
cellData?: (date: Date) => unknown;
|
|
84
94
|
/** 選択不可日付の判定。true を返した日付は is-disabled クラスになり、インタラクティブ時は選択・ホバーできなくなる */
|
|
@@ -114,28 +124,64 @@
|
|
|
114
124
|
isDateDisabled,
|
|
115
125
|
}: CalendarProps = $props();
|
|
116
126
|
|
|
127
|
+
// interactive 時のみ APG の grid セマンティクスを付与する。静的表示では
|
|
128
|
+
// ネイティブの table/cell セマンティクスをそのまま使う。
|
|
129
|
+
const gridCellRole = $derived(interactive ? "gridcell" : undefined);
|
|
130
|
+
// h2 に一意な id を振り、table は aria-labelledby で参照する。
|
|
131
|
+
// $props.id() を使うのは同じ月のカレンダーが複数同時に置かれた場合に
|
|
132
|
+
// id が衝突し aria-labelledby が別のカレンダーを見指すため。
|
|
133
|
+
const headingId = $props.id();
|
|
134
|
+
|
|
117
135
|
const cellDate = (day: number): Date => createDate(year, month - 1, day);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* 1セルぶんの表示データ(Date・状態・クラス・aria 用の状態)を1回の計算でまとめる。
|
|
139
|
+
* テンプレートはこの結果だけを参照するので、セルあたりの状態計算は1回になる。
|
|
140
|
+
*/
|
|
141
|
+
interface DayCell {
|
|
142
|
+
date: Date;
|
|
143
|
+
state: CalendarCellState;
|
|
144
|
+
className: string | undefined;
|
|
145
|
+
isSelected: boolean;
|
|
146
|
+
isCursor: boolean;
|
|
147
|
+
isDisabled: boolean;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const dayCell = (day: number): DayCell => {
|
|
151
|
+
const date = cellDate(day);
|
|
152
|
+
const state = getCalendarCellState(date, {
|
|
122
153
|
today,
|
|
123
154
|
holidayLocale,
|
|
124
155
|
highlight,
|
|
125
156
|
range,
|
|
126
|
-
rangePreview,
|
|
127
|
-
selected,
|
|
128
|
-
cursorDate,
|
|
129
|
-
hoveredDate,
|
|
130
157
|
isDateDisabled,
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
158
|
+
});
|
|
159
|
+
const className =
|
|
160
|
+
joinCellClassLists(
|
|
161
|
+
getCellStateClasses(state),
|
|
162
|
+
getSelectionCellClasses(date, {
|
|
163
|
+
rangePreview,
|
|
164
|
+
hoveredDate,
|
|
165
|
+
selected,
|
|
166
|
+
cursorDate,
|
|
167
|
+
}),
|
|
168
|
+
) || undefined;
|
|
169
|
+
return {
|
|
170
|
+
date,
|
|
171
|
+
state,
|
|
172
|
+
className,
|
|
173
|
+
isSelected: selected != null && isSameDay(date, selected),
|
|
174
|
+
isCursor: cursorDate != null && isSameDay(date, cursorDate),
|
|
175
|
+
isDisabled: state.isDisabled,
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* renderCell の戻り値が Snippet なら {@render}、文字列ならテキストとして扱う。
|
|
181
|
+
* Svelte 5 の Snippet は関数なので typeof で判別できる。
|
|
182
|
+
*/
|
|
183
|
+
const isSnippet = (value: string | Snippet): value is Snippet =>
|
|
184
|
+
typeof value === "function";
|
|
139
185
|
const weekOf = (row: (number | null)[]): number | null => {
|
|
140
186
|
const firstIdx = row.findIndex((d) => d !== null);
|
|
141
187
|
if (firstIdx === -1) return null;
|
|
@@ -145,86 +191,131 @@
|
|
|
145
191
|
? getISOWeek(weekStartDate)
|
|
146
192
|
: getWeekOfYear(weekStartDate);
|
|
147
193
|
};
|
|
148
|
-
const handleCellClick = (
|
|
194
|
+
const handleCellClick = (cell: DayCell) => {
|
|
149
195
|
if (interactive && onDateClick) {
|
|
150
|
-
|
|
151
|
-
onDateClick(date, cellData?.(date));
|
|
196
|
+
onDateClick(cell.date, cellData?.(cell.date));
|
|
152
197
|
}
|
|
153
198
|
};
|
|
154
|
-
const handleCellHover = (
|
|
155
|
-
if (interactive && onDateHover) onDateHover(
|
|
199
|
+
const handleCellHover = (cell: DayCell) => {
|
|
200
|
+
if (interactive && onDateHover) onDateHover(cell.date);
|
|
156
201
|
};
|
|
157
202
|
const handleMouseLeave = () => {
|
|
158
203
|
if (interactive && onDateLeave) onDateLeave();
|
|
159
204
|
};
|
|
160
205
|
|
|
206
|
+
// グリッド・曜日ヘッダーは月単位で不変。$derived なので年月が変わったときだけ再計算される
|
|
207
|
+
const grid = $derived(buildMonthGrid(year, month, weekStart));
|
|
208
|
+
const weekdays = $derived(getWeekdayHeaders(locale, weekStart));
|
|
209
|
+
// 週番号は表示時のみ計算する。グリッドと同じ月単位の依存
|
|
210
|
+
const weekNumbers = $derived(showWeekNumbers ? grid.map(weekOf) : null);
|
|
211
|
+
// 行ヘッダーの accessible name は行ごとに一意でなければ識別できないため
|
|
212
|
+
// ラベル+週番号を組み合わせる(aria-label が内容の数字を上書きしないように)。
|
|
213
|
+
// 関数にして locale・weekNumbers を追跡する
|
|
214
|
+
const weekAriaLabel = (i: number): string | undefined =>
|
|
215
|
+
weekNumbers !== null
|
|
216
|
+
? `${uiString("weekNumber", locale)} ${weekNumbers[i]}`
|
|
217
|
+
: undefined;
|
|
218
|
+
|
|
161
219
|
// style 属性は文字列のみ受け付けるためオブジェクトを直列化する(--cal-* 変数含む)
|
|
162
220
|
const rootStyle = $derived(
|
|
163
221
|
styleObjectToString({
|
|
164
|
-
...
|
|
222
|
+
...mergeColorScheme(colorScheme),
|
|
165
223
|
...buildSizeStyle(size),
|
|
166
224
|
...style,
|
|
167
225
|
}),
|
|
168
226
|
);
|
|
169
227
|
</script>
|
|
170
228
|
|
|
229
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
230
|
+
<!-- onmouseleave はホバー状態クリア用の補助イベント、onkeydown は
|
|
231
|
+
InteractiveCalendar が table 上で扱う。root 自体は widget ではないため
|
|
232
|
+
ARIA role は持たない。 -->
|
|
171
233
|
<div
|
|
172
234
|
class="calendar {resolveTheme(theme).className}{isSizeName(size) ? ` calendar-size-${size}` : ""}{interactive ? " calendar-interactive" : ""}{responsive ? " calendar-responsive" : ""}"
|
|
173
235
|
style={rootStyle}
|
|
174
|
-
role={interactive ? "group" : undefined}
|
|
175
236
|
onmouseleave={interactive ? handleMouseLeave : undefined}
|
|
176
237
|
onkeydown={onkeydown}
|
|
177
238
|
>
|
|
178
239
|
<div class="calendar-header">
|
|
179
|
-
|
|
240
|
+
<!--
|
|
241
|
+
見出しをそのまま live region にする。別の要素に同じ文言を複製すると
|
|
242
|
+
アクセシビリティツリー上で月名が二重に存在するため。
|
|
243
|
+
interactive 時は月が変わったことをここで読み上げる(APG Date Picker Dialog)。
|
|
244
|
+
-->
|
|
245
|
+
<h2
|
|
246
|
+
id={headingId}
|
|
247
|
+
aria-live={interactive ? "polite" : undefined}
|
|
248
|
+
aria-atomic={interactive ? "true" : undefined}
|
|
249
|
+
>
|
|
250
|
+
{getMonthName(locale, month)} {year}
|
|
251
|
+
</h2>
|
|
180
252
|
</div>
|
|
181
|
-
|
|
253
|
+
<!-- interactive 時のみ APG の grid セマンティクスを付与する。静的表示では
|
|
254
|
+
ネイティブの table/cell セマンティクスをそのまま使う。 -->
|
|
255
|
+
<table role={interactive ? "grid" : undefined} aria-labelledby={headingId}>
|
|
182
256
|
<thead>
|
|
183
257
|
<tr>
|
|
184
258
|
{#if showWeekNumbers}
|
|
185
|
-
<th class="calendar-week" scope="col" aria-label="
|
|
259
|
+
<th class="calendar-week" scope="col" aria-label={uiString("weekNumber", locale)}></th>
|
|
186
260
|
{/if}
|
|
187
|
-
{#each
|
|
261
|
+
{#each weekdays as day (day)}
|
|
188
262
|
<th scope="col">{day}</th>
|
|
189
263
|
{/each}
|
|
190
264
|
</tr>
|
|
191
265
|
</thead>
|
|
192
266
|
<tbody>
|
|
193
|
-
{#each
|
|
267
|
+
{#each grid as row, i (i)}
|
|
194
268
|
{#if !row.every((d) => d === null)}
|
|
195
269
|
<tr>
|
|
196
270
|
{#if showWeekNumbers}
|
|
197
|
-
<th
|
|
271
|
+
<th
|
|
272
|
+
class="calendar-week"
|
|
273
|
+
scope="row"
|
|
274
|
+
aria-label={weekAriaLabel(i)}
|
|
275
|
+
>{#if weekNumbers !== null}{weekNumbers[i]}{/if}</th>
|
|
198
276
|
{/if}
|
|
199
277
|
{#each row as day, j (j)}
|
|
200
278
|
{#if day === null}
|
|
201
|
-
<td></td>
|
|
279
|
+
<td role={gridCellRole} class={getBlankClasses()}></td>
|
|
202
280
|
{:else}
|
|
281
|
+
{@const cell = dayCell(day)}
|
|
203
282
|
<td
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
aria-
|
|
283
|
+
role={gridCellRole}
|
|
284
|
+
class={cell.className}
|
|
285
|
+
aria-selected={cell.isSelected || undefined}
|
|
286
|
+
aria-current={cell.state.isToday ? "date" : undefined}
|
|
287
|
+
aria-disabled={cell.isDisabled || undefined}
|
|
207
288
|
>
|
|
208
289
|
{#if interactive}
|
|
209
290
|
<button
|
|
210
291
|
type="button"
|
|
211
292
|
class="calendar-day-btn"
|
|
212
|
-
onclick={
|
|
213
|
-
onmouseenter={
|
|
214
|
-
tabindex={
|
|
215
|
-
data-cursor={
|
|
293
|
+
onclick={cell.isDisabled ? undefined : () => handleCellClick(cell)}
|
|
294
|
+
onmouseenter={cell.isDisabled ? undefined : () => handleCellHover(cell)}
|
|
295
|
+
tabindex={cell.isCursor ? 0 : -1}
|
|
296
|
+
data-cursor={cell.isCursor ? "true" : undefined}
|
|
216
297
|
aria-label={formatCellLabel(locale, year, month, day)}
|
|
217
|
-
aria-pressed={
|
|
218
|
-
disabled={
|
|
298
|
+
aria-pressed={cell.isSelected}
|
|
299
|
+
disabled={cell.isDisabled}
|
|
219
300
|
>
|
|
220
301
|
{#if renderCell}
|
|
221
|
-
{renderCell(day,
|
|
302
|
+
{@const rendered = renderCell(day, cell.date, cell.state, cellData?.(cell.date))}
|
|
303
|
+
{#if isSnippet(rendered)}
|
|
304
|
+
{@render rendered()}
|
|
305
|
+
{:else}
|
|
306
|
+
{rendered}
|
|
307
|
+
{/if}
|
|
222
308
|
{:else}
|
|
223
309
|
{day}
|
|
224
310
|
{/if}
|
|
225
311
|
</button>
|
|
226
312
|
{:else if renderCell}
|
|
227
|
-
{renderCell(day,
|
|
313
|
+
{@const rendered = renderCell(day, cell.date, cell.state, cellData?.(cell.date))}
|
|
314
|
+
{#if isSnippet(rendered)}
|
|
315
|
+
{@render rendered()}
|
|
316
|
+
{:else}
|
|
317
|
+
{rendered}
|
|
318
|
+
{/if}
|
|
228
319
|
{:else}
|
|
229
320
|
{day}
|
|
230
321
|
{/if}
|
|
@@ -2,6 +2,7 @@ import type { CalendarCellState, CalendarOptions } from "@typescript-calendar-li
|
|
|
2
2
|
import type { CalendarSize } from "./size.js";
|
|
3
3
|
import type { CSSProperties } from "./style.js";
|
|
4
4
|
import type { ColorSchemeName, SvelteColorScheme, SvelteTheme, ThemeName } from "./themes.js";
|
|
5
|
+
import type { Snippet } from "svelte";
|
|
5
6
|
interface CalendarProps {
|
|
6
7
|
year: number;
|
|
7
8
|
month: number;
|
|
@@ -49,8 +50,11 @@ interface CalendarProps {
|
|
|
49
50
|
onDateLeave?: () => void;
|
|
50
51
|
/** キーボード操作。root 要素で発火(矢印キー等を InteractiveCalendar が処理する) */
|
|
51
52
|
onkeydown?: (event: KeyboardEvent) => void;
|
|
52
|
-
/**
|
|
53
|
-
|
|
53
|
+
/**
|
|
54
|
+
* セル内容のカスタムレンダリング。interactive 時は button の子として描画される。
|
|
55
|
+
* Snippet(markup)または文字列のどちらでも受け付ける。第4引数に該当日のデータが渡る。
|
|
56
|
+
*/
|
|
57
|
+
renderCell?: (day: number, date: Date, state: CalendarCellState, data?: unknown) => string | Snippet;
|
|
54
58
|
/** 各セルに付与するユーザー定義データを解決する関数。実セルのみに呼ばれる */
|
|
55
59
|
cellData?: (date: Date) => unknown;
|
|
56
60
|
/** 選択不可日付の判定。true を返した日付は is-disabled クラスになり、インタラクティブ時は選択・ホバーできなくなる */
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { CalendarCellState, CalendarOptions } from "@typescript-calendar-lib/core";
|
|
3
|
+
import { createDate, lastDayOfMonth } from "@typescript-calendar-lib/core";
|
|
3
4
|
import type { SelectionMode } from "@typescript-calendar-lib/tui";
|
|
4
5
|
import { keyToAction } from "@typescript-calendar-lib/tui";
|
|
6
|
+
import type { Snippet } from "svelte";
|
|
5
7
|
import Calendar from "./Calendar.svelte";
|
|
6
8
|
import { buildRangePreview } from "./range-preview.js";
|
|
7
9
|
import type { CalendarSize } from "./size.js";
|
|
@@ -21,9 +23,15 @@
|
|
|
21
23
|
initialYear?: number;
|
|
22
24
|
/** 表示開始月 (1-12)。範囲外は正規化される */
|
|
23
25
|
initialMonth?: number;
|
|
26
|
+
/** 制御モードの表示年。指定すると initialYear より優先され、月移動は onMonthChange に委譲される */
|
|
27
|
+
year?: number;
|
|
28
|
+
/** 制御モードの表示月 (1-12) */
|
|
29
|
+
month?: number;
|
|
24
30
|
locale?: CalendarOptions["locale"];
|
|
25
31
|
holidayLocale?: CalendarOptions["holidayLocale"];
|
|
26
32
|
weekStart?: CalendarOptions["weekStart"];
|
|
33
|
+
/** 各週の先頭に週番号(ISO/年始基準)を表示する */
|
|
34
|
+
showWeekNumbers?: boolean;
|
|
27
35
|
/** ハイライト対象日 */
|
|
28
36
|
highlight?: Date;
|
|
29
37
|
/** 色付け範囲 */
|
|
@@ -34,6 +42,8 @@
|
|
|
34
42
|
today?: Date;
|
|
35
43
|
/** 選択不可日付の判定。true を返した日付は選択・カーソル移動・ホバーの対象外になる */
|
|
36
44
|
isDateDisabled?: (date: Date) => boolean;
|
|
45
|
+
/** 表示中の年月が変わったときに呼ばれる */
|
|
46
|
+
onMonthChange?: (year: number, month: number) => void;
|
|
37
47
|
|
|
38
48
|
// ── Calendar の見た目 ──
|
|
39
49
|
|
|
@@ -43,13 +53,13 @@
|
|
|
43
53
|
/** 狭い画面(スマホ等)でセルサイズと余白を自動調整する */
|
|
44
54
|
responsive?: boolean;
|
|
45
55
|
style?: CSSProperties;
|
|
46
|
-
/**
|
|
56
|
+
/** セル内容のカスタムレンダリング。文字列または Snippet。第4引数に該当日のデータが渡る */
|
|
47
57
|
renderCell?: (
|
|
48
58
|
day: number,
|
|
49
59
|
date: Date,
|
|
50
60
|
state: CalendarCellState,
|
|
51
61
|
data?: unknown,
|
|
52
|
-
) => string;
|
|
62
|
+
) => string | Snippet;
|
|
53
63
|
/** 各セルに付与するユーザー定義データを解決する関数。実セルのみに呼ばれる */
|
|
54
64
|
cellData?: (date: Date) => unknown;
|
|
55
65
|
|
|
@@ -69,11 +79,15 @@
|
|
|
69
79
|
locale,
|
|
70
80
|
holidayLocale,
|
|
71
81
|
weekStart,
|
|
82
|
+
showWeekNumbers,
|
|
72
83
|
highlight,
|
|
73
84
|
range,
|
|
74
85
|
selectionMode,
|
|
75
86
|
today,
|
|
76
87
|
isDateDisabled,
|
|
88
|
+
year,
|
|
89
|
+
month,
|
|
90
|
+
onMonthChange,
|
|
77
91
|
theme,
|
|
78
92
|
colorScheme,
|
|
79
93
|
size,
|
|
@@ -89,6 +103,8 @@
|
|
|
89
103
|
const cal = useCalendarState(() => ({
|
|
90
104
|
initialYear,
|
|
91
105
|
initialMonth,
|
|
106
|
+
year,
|
|
107
|
+
month,
|
|
92
108
|
locale,
|
|
93
109
|
holidayLocale,
|
|
94
110
|
weekStart,
|
|
@@ -97,6 +113,7 @@
|
|
|
97
113
|
range,
|
|
98
114
|
isDateDisabled,
|
|
99
115
|
selectionMode,
|
|
116
|
+
onMonthChange,
|
|
100
117
|
}));
|
|
101
118
|
|
|
102
119
|
// クリック(マウス・Enter/Space 共通)で日付を選択する。
|
|
@@ -134,7 +151,7 @@
|
|
|
134
151
|
});
|
|
135
152
|
|
|
136
153
|
const handleKeyDown = (event: KeyboardEvent) => {
|
|
137
|
-
const action = keyToAction(event.key);
|
|
154
|
+
const action = keyToAction(event.key, event);
|
|
138
155
|
if (action === undefined) return;
|
|
139
156
|
event.preventDefault();
|
|
140
157
|
switch (action) {
|
|
@@ -144,6 +161,21 @@
|
|
|
144
161
|
case "next":
|
|
145
162
|
cal.goNext();
|
|
146
163
|
break;
|
|
164
|
+
case "prevYear":
|
|
165
|
+
cal.navigateYear("prev");
|
|
166
|
+
break;
|
|
167
|
+
case "nextYear":
|
|
168
|
+
cal.navigateYear("next");
|
|
169
|
+
break;
|
|
170
|
+
case "firstDay":
|
|
171
|
+
cal.setCursorToDate(createDate(cal.state.year, cal.state.month - 1, 1));
|
|
172
|
+
break;
|
|
173
|
+
case "lastDay":
|
|
174
|
+
cal.setCursorToDate(lastDayOfMonth(cal.state.year, cal.state.month));
|
|
175
|
+
break;
|
|
176
|
+
case "clear":
|
|
177
|
+
cal.clearSelection();
|
|
178
|
+
break;
|
|
147
179
|
default:
|
|
148
180
|
cal.moveCursor(action);
|
|
149
181
|
}
|
|
@@ -157,6 +189,7 @@
|
|
|
157
189
|
locale={cal.state.options.locale}
|
|
158
190
|
holidayLocale={cal.state.options.holidayLocale}
|
|
159
191
|
weekStart={cal.state.options.weekStart}
|
|
192
|
+
showWeekNumbers={showWeekNumbers}
|
|
160
193
|
highlight={cal.state.options.highlight}
|
|
161
194
|
range={cal.state.options.range}
|
|
162
195
|
today={cal.state.options.today}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CalendarCellState, CalendarOptions } from "@typescript-calendar-lib/core";
|
|
2
2
|
import type { SelectionMode } from "@typescript-calendar-lib/tui";
|
|
3
|
+
import type { Snippet } from "svelte";
|
|
3
4
|
import type { CalendarSize } from "./size.js";
|
|
4
5
|
import type { CSSProperties } from "./style.js";
|
|
5
6
|
import type { ColorSchemeName, SvelteColorScheme, SvelteTheme, ThemeName } from "./themes.js";
|
|
@@ -8,9 +9,15 @@ interface InteractiveCalendarProps {
|
|
|
8
9
|
initialYear?: number;
|
|
9
10
|
/** 表示開始月 (1-12)。範囲外は正規化される */
|
|
10
11
|
initialMonth?: number;
|
|
12
|
+
/** 制御モードの表示年。指定すると initialYear より優先され、月移動は onMonthChange に委譲される */
|
|
13
|
+
year?: number;
|
|
14
|
+
/** 制御モードの表示月 (1-12) */
|
|
15
|
+
month?: number;
|
|
11
16
|
locale?: CalendarOptions["locale"];
|
|
12
17
|
holidayLocale?: CalendarOptions["holidayLocale"];
|
|
13
18
|
weekStart?: CalendarOptions["weekStart"];
|
|
19
|
+
/** 各週の先頭に週番号(ISO/年始基準)を表示する */
|
|
20
|
+
showWeekNumbers?: boolean;
|
|
14
21
|
/** ハイライト対象日 */
|
|
15
22
|
highlight?: Date;
|
|
16
23
|
/** 色付け範囲 */
|
|
@@ -24,14 +31,16 @@ interface InteractiveCalendarProps {
|
|
|
24
31
|
today?: Date;
|
|
25
32
|
/** 選択不可日付の判定。true を返した日付は選択・カーソル移動・ホバーの対象外になる */
|
|
26
33
|
isDateDisabled?: (date: Date) => boolean;
|
|
34
|
+
/** 表示中の年月が変わったときに呼ばれる */
|
|
35
|
+
onMonthChange?: (year: number, month: number) => void;
|
|
27
36
|
theme?: ThemeName | SvelteTheme;
|
|
28
37
|
colorScheme?: ColorSchemeName | SvelteColorScheme;
|
|
29
38
|
size?: CalendarSize;
|
|
30
39
|
/** 狭い画面(スマホ等)でセルサイズと余白を自動調整する */
|
|
31
40
|
responsive?: boolean;
|
|
32
41
|
style?: CSSProperties;
|
|
33
|
-
/**
|
|
34
|
-
renderCell?: (day: number, date: Date, state: CalendarCellState, data?: unknown) => string;
|
|
42
|
+
/** セル内容のカスタムレンダリング。文字列または Snippet。第4引数に該当日のデータが渡る */
|
|
43
|
+
renderCell?: (day: number, date: Date, state: CalendarCellState, data?: unknown) => string | Snippet;
|
|
35
44
|
/** 各セルに付与するユーザー定義データを解決する関数。実セルのみに呼ばれる */
|
|
36
45
|
cellData?: (date: Date) => unknown;
|
|
37
46
|
/** セルクリック時(キーボードの Enter/Space 含む)。クリックした日付は自動的に選択される。第2引数に該当日のデータが渡る */
|
package/dist/calendar.css
CHANGED
|
@@ -2,18 +2,20 @@
|
|
|
2
2
|
--cal-bg: #fff;
|
|
3
3
|
--cal-fg: #1e293b;
|
|
4
4
|
--cal-accent: #dc2626;
|
|
5
|
-
--cal-weekend-fg: #
|
|
5
|
+
--cal-weekend-fg: #586a84;
|
|
6
6
|
--cal-holiday-fg: #d33;
|
|
7
|
-
--cal-border: #
|
|
7
|
+
--cal-border: #aeb8c6;
|
|
8
8
|
--cal-header-bg: #f8fafc;
|
|
9
9
|
--cal-highlight-bg: #dc2626;
|
|
10
10
|
--cal-highlight-fg: #fff;
|
|
11
11
|
--cal-range-bg: #fef3c7;
|
|
12
|
+
--cal-range-preview-bg: #fef9c3;
|
|
13
|
+
--cal-hover-bg: #fef9c3;
|
|
12
14
|
--cal-today-bg: #fff7ed;
|
|
13
15
|
--cal-today-fg: #c2410c;
|
|
14
16
|
--cal-selected-bg: #dc2626;
|
|
15
17
|
--cal-selected-fg: #fff;
|
|
16
|
-
--cal-disabled-fg: #
|
|
18
|
+
--cal-disabled-fg: #5b799d;
|
|
17
19
|
--cal-cell-w: 2.25rem;
|
|
18
20
|
--cal-cell-h: 2rem;
|
|
19
21
|
--cal-font-size: .875rem;
|
|
@@ -75,7 +77,6 @@
|
|
|
75
77
|
|
|
76
78
|
.calendar td.is-disabled {
|
|
77
79
|
color: var(--cal-disabled-fg, var(--cal-weekend-fg));
|
|
78
|
-
opacity: .5;
|
|
79
80
|
text-decoration: line-through;
|
|
80
81
|
}
|
|
81
82
|
|
|
@@ -168,7 +169,7 @@
|
|
|
168
169
|
border: 1px solid var(--cal-border);
|
|
169
170
|
}
|
|
170
171
|
|
|
171
|
-
.calendar-theme-modern td
|
|
172
|
+
.calendar-theme-modern td.is-blank {
|
|
172
173
|
background: none;
|
|
173
174
|
border-color: #0000;
|
|
174
175
|
}
|
|
@@ -223,11 +224,11 @@
|
|
|
223
224
|
border-radius: 999px;
|
|
224
225
|
}
|
|
225
226
|
|
|
226
|
-
.calendar-theme-rounded td
|
|
227
|
+
.calendar-theme-rounded td.is-blank {
|
|
227
228
|
background: none;
|
|
228
229
|
}
|
|
229
230
|
|
|
230
|
-
.calendar-interactive {
|
|
231
|
+
.calendar-interactive:focus:not(:focus-visible) {
|
|
231
232
|
outline: none;
|
|
232
233
|
}
|
|
233
234
|
|
|
@@ -343,8 +344,63 @@
|
|
|
343
344
|
@media (width <= 360px) {
|
|
344
345
|
.calendar-responsive {
|
|
345
346
|
--cal-cell-w: 1.5rem;
|
|
346
|
-
--cal-cell-h: 1.
|
|
347
|
+
--cal-cell-h: 1.5rem;
|
|
347
348
|
--cal-font-size: .6875rem;
|
|
348
349
|
--cal-header-font-size: .875rem;
|
|
349
350
|
}
|
|
350
351
|
}
|
|
352
|
+
|
|
353
|
+
.calendar-sr-only {
|
|
354
|
+
clip-path: inset(50%);
|
|
355
|
+
white-space: nowrap;
|
|
356
|
+
border: 0;
|
|
357
|
+
width: 1px;
|
|
358
|
+
height: 1px;
|
|
359
|
+
margin: -1px;
|
|
360
|
+
padding: 0;
|
|
361
|
+
position: absolute;
|
|
362
|
+
overflow: hidden;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
@media (prefers-reduced-motion: reduce) {
|
|
366
|
+
.calendar-interactive td button.calendar-day-btn {
|
|
367
|
+
transition: none;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
.calendar-interactive td button.calendar-day-btn:active {
|
|
371
|
+
transform: none;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
@media (forced-colors: active) {
|
|
376
|
+
.calendar td.is-today, .calendar td.is-highlight, .calendar td.is-in-range, .calendar td.is-in-range-preview {
|
|
377
|
+
color: canvastext;
|
|
378
|
+
forced-color-adjust: none;
|
|
379
|
+
background: canvas;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
.calendar td.is-in-range, .calendar td.is-in-range-preview {
|
|
383
|
+
border: 1px dashed highlight;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
.calendar td.is-in-range-preview {
|
|
387
|
+
border-style: dotted;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
.calendar td.is-selected {
|
|
391
|
+
color: highlighttext;
|
|
392
|
+
forced-color-adjust: none;
|
|
393
|
+
outline-offset: -2px;
|
|
394
|
+
background: highlight;
|
|
395
|
+
outline: 2px solid highlight;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
.calendar td.is-disabled {
|
|
399
|
+
color: graytext;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
.calendar td.is-cursor, .calendar-interactive td button.calendar-day-btn:focus-visible {
|
|
403
|
+
outline-offset: -2px;
|
|
404
|
+
outline: 2px solid canvastext;
|
|
405
|
+
}
|
|
406
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import Calendar from "./Calendar.svelte";
|
|
|
2
2
|
import InteractiveCalendar from "./InteractiveCalendar.svelte";
|
|
3
3
|
export { Calendar, InteractiveCalendar };
|
|
4
4
|
export default Calendar;
|
|
5
|
-
export type { CellStateOptions } from "
|
|
6
|
-
export { getCellClasses } from "
|
|
5
|
+
export type { CellStateOptions, SelectionCellOptions, } from "@typescript-calendar-lib/web";
|
|
6
|
+
export { getBlankClasses, getCellClasses, getCellStateClasses, getSelectionCellClasses, joinCellClassLists, } from "@typescript-calendar-lib/web";
|
|
7
7
|
export { buildRangePreview } from "./range-preview.js";
|
|
8
8
|
export type { CalendarCustomSize, CalendarSize, CalendarSizeName, } from "./size.js";
|
|
9
9
|
export { buildSizeStyle, isSizeName } from "./size.js";
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import Calendar from "./Calendar.svelte";
|
|
|
2
2
|
import InteractiveCalendar from "./InteractiveCalendar.svelte";
|
|
3
3
|
export { Calendar, InteractiveCalendar };
|
|
4
4
|
export default Calendar;
|
|
5
|
-
export { getCellClasses } from "
|
|
5
|
+
export { getBlankClasses, getCellClasses, getCellStateClasses, getSelectionCellClasses, joinCellClassLists, } from "@typescript-calendar-lib/web";
|
|
6
6
|
export { buildRangePreview } from "./range-preview.js";
|
|
7
7
|
export { buildSizeStyle, isSizeName } from "./size.js";
|
|
8
8
|
export { COLOR_SCHEMES, resolveColorScheme, resolveTheme, THEMES, } from "./themes.js";
|
package/dist/themes.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { WebColorScheme, WebTheme } from "@typescript-calendar-lib/web";
|
|
2
|
-
export type { ColorSchemeName, ThemeName, } from "@typescript-calendar-lib/web";
|
|
3
|
-
export { COLOR_SCHEMES, resolveColorScheme, resolveTheme, THEMES, } from "@typescript-calendar-lib/web";
|
|
2
|
+
export type { ColorSchemeName, MergedColorScheme, ThemeName, } from "@typescript-calendar-lib/web";
|
|
3
|
+
export { COLOR_SCHEMES, mergeColorScheme, resolveColorScheme, resolveTheme, THEMES, } from "@typescript-calendar-lib/web";
|
|
4
4
|
/** Svelte の見た目定義(web の WebTheme と同一構造) */
|
|
5
5
|
export type SvelteTheme = WebTheme;
|
|
6
6
|
/** CSS カスタムプロパティ(--cal-*)の値マップ */
|
package/dist/themes.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// ─── テーマ ───────────────────────────────────────────────
|
|
2
2
|
// テーマ定義・カラースキームは web パッケージに集約済み。
|
|
3
3
|
// Svelte 固有の型名(SvelteTheme / SvelteColorScheme)だけをこの層で別名定義する。
|
|
4
|
-
export { COLOR_SCHEMES, resolveColorScheme, resolveTheme, THEMES, } from "@typescript-calendar-lib/web";
|
|
4
|
+
export { COLOR_SCHEMES, mergeColorScheme, resolveColorScheme, resolveTheme, THEMES, } from "@typescript-calendar-lib/web";
|
|
@@ -3,6 +3,15 @@ import type { CalendarState, CalendarStateOptions, Direction, MonthDirection } f
|
|
|
3
3
|
export interface UseCalendarStateOptions extends Pick<CalendarStateOptions, "locale" | "holidayLocale" | "weekStart" | "today" | "highlight" | "range" | "isDateDisabled" | "selectionMode"> {
|
|
4
4
|
initialYear?: number;
|
|
5
5
|
initialMonth?: number;
|
|
6
|
+
/**
|
|
7
|
+
* 制御モードの表示年。指定すると `initialYear` より優先され、値が変わるたびに
|
|
8
|
+
* その年月へ再構築される。月移動は内部状態を変えず `onMonthChange` に通知する。
|
|
9
|
+
*/
|
|
10
|
+
year?: number;
|
|
11
|
+
/** 制御モードの表示月 (1–12)。`year` と併用する */
|
|
12
|
+
month?: number;
|
|
13
|
+
/** 表示中の年月が変わったときに呼ばれる */
|
|
14
|
+
onMonthChange?: (year: number, month: number) => void;
|
|
6
15
|
}
|
|
7
16
|
/**
|
|
8
17
|
* `useCalendarState` の first 引数。
|
|
@@ -20,6 +29,12 @@ export interface UseCalendarStateReturn {
|
|
|
20
29
|
/** 前月/翌月へ移動 */
|
|
21
30
|
goNext: () => void;
|
|
22
31
|
goPrev: () => void;
|
|
32
|
+
/** 前年/翌年へ移動 */
|
|
33
|
+
navigateYear: (direction: MonthDirection) => void;
|
|
34
|
+
/** 指定した年月へジャンプ */
|
|
35
|
+
goToMonth: (year: number, month: number) => void;
|
|
36
|
+
/** 指定した日付の月へジャンプし、カーソルをその日付に置く */
|
|
37
|
+
goToDate: (date: Date) => void;
|
|
23
38
|
/** 今日の月へジャンプ */
|
|
24
39
|
goToday: () => void;
|
|
25
40
|
/** カーソル位置の日付を選択 */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { clearSelection, createCalendarState, getCursorDate, getSelectedDate, getSelectedRange, goToToday, moveCursor, navigateMonth, sameStateOptions, selectDate, selectDateAt, selectRange, setCursorToDate, updateStateOptions, } from "@typescript-calendar-lib/tui";
|
|
1
|
+
import { clearSelection, createCalendarState, getCursorDate, getSelectedDate, getSelectedRange, goToDate, goToMonth, goToToday, moveCursor, navigateMonth, navigateYear, sameStateOptions, selectDate, selectDateAt, selectRange, setCursorToDate, updateStateOptions, } from "@typescript-calendar-lib/tui";
|
|
2
2
|
/** undefined を含む日付を値(時刻)で比較する */
|
|
3
3
|
/**
|
|
4
4
|
* tui の不変状態機械を包む Svelte 5 (runes) のリアクティブ状態。
|
|
@@ -50,15 +50,36 @@ export function useCalendarState(options = {}) {
|
|
|
50
50
|
prev = next;
|
|
51
51
|
state = updateStateOptions(state, next, previous);
|
|
52
52
|
});
|
|
53
|
-
//
|
|
53
|
+
// 表示月が変わったら onMonthChange を通知し、古い月を指すホバーをクリアする。
|
|
54
|
+
// 制御モードでは props 側が月を決めているので再通知しない(二重通知の抑止)。
|
|
54
55
|
let prevMonthKey = null;
|
|
55
56
|
$effect(() => {
|
|
56
57
|
const key = `${state.year}-${state.month}`;
|
|
57
58
|
if (prevMonthKey !== null && key !== prevMonthKey) {
|
|
58
59
|
hoveredDate = null;
|
|
60
|
+
const current = getter();
|
|
61
|
+
if (current.year === undefined && current.month === undefined) {
|
|
62
|
+
current.onMonthChange?.(state.year, state.month);
|
|
63
|
+
}
|
|
59
64
|
}
|
|
60
65
|
prevMonthKey = key;
|
|
61
66
|
});
|
|
67
|
+
/** 制御モードか(year/month のどちらかが指定されている) */
|
|
68
|
+
const isControlled = () => {
|
|
69
|
+
const current = getter();
|
|
70
|
+
return current.year !== undefined || current.month !== undefined;
|
|
71
|
+
};
|
|
72
|
+
/** 制御モードなら onMonthChange に委譲し、そうでなければ状態を更新する */
|
|
73
|
+
const applyNavigation = (next) => {
|
|
74
|
+
if (isControlled()) {
|
|
75
|
+
const current = getter();
|
|
76
|
+
if (next.year !== state.year || next.month !== state.month) {
|
|
77
|
+
current.onMonthChange?.(next.year, next.month);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
state = next;
|
|
82
|
+
};
|
|
62
83
|
return {
|
|
63
84
|
get state() {
|
|
64
85
|
return state;
|
|
@@ -79,13 +100,22 @@ export function useCalendarState(options = {}) {
|
|
|
79
100
|
state = moveCursor(state, direction);
|
|
80
101
|
},
|
|
81
102
|
goNext: () => {
|
|
82
|
-
|
|
103
|
+
applyNavigation(navigateMonth(state, "next"));
|
|
83
104
|
},
|
|
84
105
|
goPrev: () => {
|
|
85
|
-
|
|
106
|
+
applyNavigation(navigateMonth(state, "prev"));
|
|
107
|
+
},
|
|
108
|
+
navigateYear: (direction) => {
|
|
109
|
+
applyNavigation(navigateYear(state, direction));
|
|
110
|
+
},
|
|
111
|
+
goToMonth: (year, month) => {
|
|
112
|
+
applyNavigation(goToMonth(state, year, month));
|
|
113
|
+
},
|
|
114
|
+
goToDate: (date) => {
|
|
115
|
+
applyNavigation(goToDate(state, date));
|
|
86
116
|
},
|
|
87
117
|
goToday: () => {
|
|
88
|
-
|
|
118
|
+
applyNavigation(goToToday(state));
|
|
89
119
|
},
|
|
90
120
|
selectDate: () => {
|
|
91
121
|
state = selectDate(state);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typescript-calendar-lib/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Svelte 5 components and reactive state for typescript-calendar-lib",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"svelte": "^5"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@typescript-calendar-lib/core": "^0.
|
|
38
|
-
"@typescript-calendar-lib/tui": "^0.
|
|
39
|
-
"@typescript-calendar-lib/web": "^0.
|
|
37
|
+
"@typescript-calendar-lib/core": "^0.6.1",
|
|
38
|
+
"@typescript-calendar-lib/tui": "^0.6.1",
|
|
39
|
+
"@typescript-calendar-lib/web": "^0.6.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@sveltejs/package": "^2.5.8",
|
|
43
|
-
"@sveltejs/vite-plugin-svelte": "^7.3.
|
|
43
|
+
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|
|
44
44
|
"@testing-library/jest-dom": "^7.0.1",
|
|
45
45
|
"@testing-library/svelte": "^5",
|
|
46
46
|
"jsdom": "^30",
|
|
@@ -48,6 +48,17 @@
|
|
|
48
48
|
"typescript": "^5.9.0",
|
|
49
49
|
"vitest": "^5"
|
|
50
50
|
},
|
|
51
|
+
"author": "nazozokc",
|
|
52
|
+
"homepage": "https://github.com/nazozokc/typescript-calendar-lib#readme",
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/nazozokc/typescript-calendar-lib/issues"
|
|
55
|
+
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=22"
|
|
58
|
+
},
|
|
59
|
+
"sideEffects": [
|
|
60
|
+
"**/*.css"
|
|
61
|
+
],
|
|
51
62
|
"scripts": {
|
|
52
63
|
"build": "svelte-package -i src && cp ../web/dist/calendar.css dist/calendar.css",
|
|
53
64
|
"typecheck": "svelte-check --tsconfig ./tsconfig.json --fail-on-warnings"
|
package/dist/cell-classes.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { Locale } from "@typescript-calendar-lib/core";
|
|
2
|
-
export interface CellStateOptions {
|
|
3
|
-
today?: Date;
|
|
4
|
-
/** 祝日の判定に使うロケール。省略時は "ja" */
|
|
5
|
-
holidayLocale?: Locale;
|
|
6
|
-
highlight?: Date;
|
|
7
|
-
range?: {
|
|
8
|
-
from: Date;
|
|
9
|
-
to: Date;
|
|
10
|
-
};
|
|
11
|
-
/** 範囲プレビュー(ホバー等の候補範囲)。is-in-range-preview クラスになる */
|
|
12
|
-
rangePreview?: {
|
|
13
|
-
from: Date;
|
|
14
|
-
to: Date;
|
|
15
|
-
};
|
|
16
|
-
/** ホバー中の日付。is-hovered クラスになる */
|
|
17
|
-
hoveredDate?: Date | null;
|
|
18
|
-
/** 選択済み日付。該当セルに is-selected クラスが付く */
|
|
19
|
-
selected?: Date | null;
|
|
20
|
-
/** カーソル位置の日付。該当セルに is-cursor クラスが付く */
|
|
21
|
-
cursorDate?: Date | null;
|
|
22
|
-
/** 選択不可日付の判定。該当セルに is-disabled クラスが付く */
|
|
23
|
-
isDateDisabled?: (date: Date) => boolean;
|
|
24
|
-
}
|
|
25
|
-
/** 日付セルの状態(週末・今日・ハイライト・範囲・選択・カーソル)に応じたCSSクラスを組み立てる */
|
|
26
|
-
export declare function getCellClasses(date: Date, options: CellStateOptions): string;
|
package/dist/cell-classes.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { getCalendarCellState, isDateInRange, isSameDay, } from "@typescript-calendar-lib/core";
|
|
2
|
-
// 範囲の from > to は不正入力として RangeError(isDateInRange が検証する)
|
|
3
|
-
/** 日付セルの状態(週末・今日・ハイライト・範囲・選択・カーソル)に応じたCSSクラスを組み立てる */
|
|
4
|
-
export function getCellClasses(date, options) {
|
|
5
|
-
const state = getCalendarCellState(date, options);
|
|
6
|
-
const classes = [];
|
|
7
|
-
if (state.isWeekend)
|
|
8
|
-
classes.push("is-weekend");
|
|
9
|
-
if (state.isHoliday)
|
|
10
|
-
classes.push("is-holiday");
|
|
11
|
-
if (state.isToday)
|
|
12
|
-
classes.push("is-today");
|
|
13
|
-
if (state.isHighlight)
|
|
14
|
-
classes.push("is-highlight");
|
|
15
|
-
if (state.isInRange)
|
|
16
|
-
classes.push("is-in-range");
|
|
17
|
-
if (options.rangePreview !== undefined &&
|
|
18
|
-
isDateInRange(date, options.rangePreview))
|
|
19
|
-
classes.push("is-in-range-preview");
|
|
20
|
-
if (state.isDisabled)
|
|
21
|
-
classes.push("is-disabled");
|
|
22
|
-
if (options.hoveredDate != null && isSameDay(date, options.hoveredDate))
|
|
23
|
-
classes.push("is-hovered");
|
|
24
|
-
if (options.selected != null && isSameDay(date, options.selected))
|
|
25
|
-
classes.push("is-selected");
|
|
26
|
-
if (options.cursorDate != null && isSameDay(date, options.cursorDate))
|
|
27
|
-
classes.push("is-cursor");
|
|
28
|
-
return classes.join(" ");
|
|
29
|
-
}
|