v-calendar-3 1.0.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/LICENSE +9 -0
- package/README.md +142 -0
- package/dist/cjs/index.css +1133 -0
- package/dist/cjs/index.js +10699 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/es/index.js +10678 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/style.css +1134 -0
- package/dist/iife/index.js +2 -0
- package/dist/iife/index.js.map +1 -0
- package/dist/mjs/index.mjs +10678 -0
- package/dist/mjs/index.mjs.map +1 -0
- package/dist/mjs/style.css +1134 -0
- package/dist/style.css +1134 -0
- package/dist/types/components/BaseIcon/BaseIcon.vue.d.ts +41 -0
- package/dist/types/components/BaseIcon/icons/IconChevronDown.vue.d.ts +3 -0
- package/dist/types/components/BaseIcon/icons/IconChevronLeft.vue.d.ts +3 -0
- package/dist/types/components/BaseIcon/icons/IconChevronRight.vue.d.ts +3 -0
- package/dist/types/components/BaseIcon/icons/IconClock.vue.d.ts +3 -0
- package/dist/types/components/BaseIcon/icons/index.d.ts +4 -0
- package/dist/types/components/BaseSelect/BaseSelect.vue.d.ts +26 -0
- package/dist/types/components/Calendar/Calendar.vue.d.ts +2526 -0
- package/dist/types/components/Calendar/CalendarDay.vue.d.ts +83 -0
- package/dist/types/components/Calendar/CalendarDayPopover.vue.d.ts +3 -0
- package/dist/types/components/Calendar/CalendarHeader.vue.d.ts +13 -0
- package/dist/types/components/Calendar/CalendarNav.vue.d.ts +4 -0
- package/dist/types/components/Calendar/CalendarNavPopover.vue.d.ts +3 -0
- package/dist/types/components/Calendar/CalendarPage.vue.d.ts +3 -0
- package/dist/types/components/Calendar/CalendarPageProvider.vue.d.ts +17 -0
- package/dist/types/components/Calendar/CalendarSlot.vue.d.ts +15 -0
- package/dist/types/components/Calendar/CalendarTitleSelect.vue.d.ts +15 -0
- package/dist/types/components/CalendarGrid/CalendarCell.vue.d.ts +9 -0
- package/dist/types/components/CalendarGrid/CalendarCellPopover.vue.d.ts +209 -0
- package/dist/types/components/CalendarGrid/CalendarDayCell.vue.d.ts +8 -0
- package/dist/types/components/CalendarGrid/CalendarEventDetails.vue.d.ts +15 -0
- package/dist/types/components/CalendarGrid/CalendarEventEdit.vue.d.ts +26 -0
- package/dist/types/components/CalendarGrid/CalendarGrid.vue.d.ts +134 -0
- package/dist/types/components/CalendarGrid/CalendarGridWeek.vue.d.ts +8 -0
- package/dist/types/components/CalendarGrid/CalendarViewSelect.vue.d.ts +3 -0
- package/dist/types/components/CalendarGrid/CalendarWeekCell.vue.d.ts +10 -0
- package/dist/types/components/CalendarGrid/Constraints.d.ts +16 -0
- package/dist/types/components/DatePicker/DatePicker.vue.d.ts +15251 -0
- package/dist/types/components/DatePicker/DatePickerBase.vue.d.ts +3 -0
- package/dist/types/components/DatePicker/DatePickerPopover.vue.d.ts +3 -0
- package/dist/types/components/DatePicker/TimePicker.vue.d.ts +10089 -0
- package/dist/types/components/Popover/Popover.vue.d.ts +72 -0
- package/dist/types/components/Popover/PopoverRow.vue.d.ts +17 -0
- package/dist/types/components/index.d.ts +4 -0
- package/dist/types/index.d.cts +40981 -0
- package/dist/types/index.d.mts +40981 -0
- package/dist/types/index.d.ts +40981 -0
- package/dist/types/use/base.d.ts +67 -0
- package/dist/types/use/calendar.d.ts +2422 -0
- package/dist/types/use/calendarGrid.d.ts +9370 -0
- package/dist/types/use/datePicker.d.ts +20210 -0
- package/dist/types/use/page.d.ts +20 -0
- package/dist/types/use/slots.d.ts +5 -0
- package/dist/types/use/timePicker.d.ts +10089 -0
- package/dist/types/utils/attribute.d.ts +49 -0
- package/dist/types/utils/cache.d.ts +10 -0
- package/dist/types/utils/calendar/event.d.ts +111 -0
- package/dist/types/utils/config/index.d.ts +5 -0
- package/dist/types/utils/date/helpers.d.ts +161 -0
- package/dist/types/utils/date/range.d.ts +74 -0
- package/dist/types/utils/date/repeat.d.ts +34 -0
- package/dist/types/utils/date/rules.d.ts +82 -0
- package/dist/types/utils/defaults/index.d.ts +30 -0
- package/dist/types/utils/defaults/locales.d.ts +9 -0
- package/dist/types/utils/glyph.d.ts +58 -0
- package/dist/types/utils/helpers.d.ts +49 -0
- package/dist/types/utils/locale.d.ts +48 -0
- package/dist/types/utils/page.d.ts +95 -0
- package/dist/types/utils/plugins/index.d.ts +4 -0
- package/dist/types/utils/popovers.d.ts +47 -0
- package/dist/types/utils/theme.d.ts +17 -0
- package/dist/types/utils/touch.d.ts +8 -0
- package/dist/types/utils/useDisplayMode.d.ts +12 -0
- package/dist/types/utils/watchers.d.ts +6 -0
- package/package.json +115 -0
- package/src/components/BaseIcon/BaseIcon.vue +29 -0
- package/src/components/BaseIcon/icons/IconChevronDown.vue +5 -0
- package/src/components/BaseIcon/icons/IconChevronLeft.vue +5 -0
- package/src/components/BaseIcon/icons/IconChevronRight.vue +5 -0
- package/src/components/BaseIcon/icons/IconClock.vue +11 -0
- package/src/components/BaseIcon/icons/index.ts +4 -0
- package/src/components/BaseSelect/BaseSelect.vue +136 -0
- package/src/components/Calendar/Calendar.vue +116 -0
- package/src/components/Calendar/CalendarDay.vue +422 -0
- package/src/components/Calendar/CalendarDayPopover.vue +44 -0
- package/src/components/Calendar/CalendarHeader.vue +203 -0
- package/src/components/Calendar/CalendarNav.vue +325 -0
- package/src/components/Calendar/CalendarNavPopover.vue +24 -0
- package/src/components/Calendar/CalendarPage.vue +140 -0
- package/src/components/Calendar/CalendarPageProvider.vue +15 -0
- package/src/components/Calendar/CalendarSlot.vue +36 -0
- package/src/components/Calendar/CalendarTitleSelect.vue +72 -0
- package/src/components/CalendarGrid/CalendarCell.vue +112 -0
- package/src/components/CalendarGrid/CalendarCellPopover.vue +93 -0
- package/src/components/CalendarGrid/CalendarDayCell.vue +57 -0
- package/src/components/CalendarGrid/CalendarEventDetails.vue +71 -0
- package/src/components/CalendarGrid/CalendarEventEdit.vue +195 -0
- package/src/components/CalendarGrid/CalendarGrid.vue +715 -0
- package/src/components/CalendarGrid/CalendarGridWeek.vue +60 -0
- package/src/components/CalendarGrid/CalendarViewSelect.vue +34 -0
- package/src/components/CalendarGrid/CalendarWeekCell.vue +52 -0
- package/src/components/CalendarGrid/Constraints.ts +40 -0
- package/src/components/DatePicker/DatePicker.vue +27 -0
- package/src/components/DatePicker/DatePickerBase.vue +53 -0
- package/src/components/DatePicker/DatePickerPopover.vue +37 -0
- package/src/components/DatePicker/TimePicker.vue +167 -0
- package/src/components/Popover/Popover.vue +572 -0
- package/src/components/Popover/PopoverRow.vue +94 -0
- package/src/components/index.ts +4 -0
- package/src/index.ts +24 -0
- package/src/styles/index.css +48 -0
- package/src/styles/theme.css +322 -0
- package/src/styles/transitions.css +77 -0
- package/src/use/base.ts +144 -0
- package/src/use/calendar.ts +796 -0
- package/src/use/calendarGrid.ts +954 -0
- package/src/use/datePicker.ts +909 -0
- package/src/use/page.ts +78 -0
- package/src/use/slots.ts +17 -0
- package/src/use/timePicker.ts +194 -0
- package/src/utils/attribute.ts +107 -0
- package/src/utils/cache.ts +30 -0
- package/src/utils/calendar/event.ts +335 -0
- package/src/utils/config/index.ts +11 -0
- package/src/utils/date/helpers.ts +1039 -0
- package/src/utils/date/range.ts +274 -0
- package/src/utils/date/repeat.ts +135 -0
- package/src/utils/date/rules.ts +290 -0
- package/src/utils/defaults/index.ts +77 -0
- package/src/utils/defaults/locales.ts +123 -0
- package/src/utils/defaults/masks.json +15 -0
- package/src/utils/defaults/touch.json +5 -0
- package/src/utils/glyph.ts +305 -0
- package/src/utils/helpers.ts +181 -0
- package/src/utils/locale.ts +275 -0
- package/src/utils/page.ts +608 -0
- package/src/utils/plugins/index.ts +24 -0
- package/src/utils/popovers.ts +216 -0
- package/src/utils/theme.ts +58 -0
- package/src/utils/touch.ts +72 -0
- package/src/utils/useDisplayMode.ts +198 -0
- package/src/utils/watchers.ts +26 -0
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type PageConfig,
|
|
3
|
+
type CachedPage,
|
|
4
|
+
getPageKey,
|
|
5
|
+
getCachedPage,
|
|
6
|
+
getPage,
|
|
7
|
+
} from './page';
|
|
8
|
+
import {
|
|
9
|
+
type DateSource,
|
|
10
|
+
type DateOptions,
|
|
11
|
+
type DayOfWeek,
|
|
12
|
+
type MonthParts,
|
|
13
|
+
type MonthInYear,
|
|
14
|
+
type SimpleDateParts,
|
|
15
|
+
type TimeNames,
|
|
16
|
+
DatePatchKeys,
|
|
17
|
+
applyRulesForDateParts,
|
|
18
|
+
daysInWeek,
|
|
19
|
+
formatDate,
|
|
20
|
+
parseDate,
|
|
21
|
+
getDateParts,
|
|
22
|
+
getDateFromParts,
|
|
23
|
+
getDayNames,
|
|
24
|
+
getMonthNames,
|
|
25
|
+
getMonthParts,
|
|
26
|
+
getMonthPartsKey,
|
|
27
|
+
getHourDates,
|
|
28
|
+
getRelativeTimeNames,
|
|
29
|
+
isDateParts,
|
|
30
|
+
} from './date/helpers';
|
|
31
|
+
import Cache from './cache';
|
|
32
|
+
import { type DateRangeSource, DateRange } from './date/range';
|
|
33
|
+
import { defaultLocales } from './defaults';
|
|
34
|
+
import {
|
|
35
|
+
isString,
|
|
36
|
+
isNumber,
|
|
37
|
+
isDate,
|
|
38
|
+
isObject,
|
|
39
|
+
has,
|
|
40
|
+
pick,
|
|
41
|
+
clamp,
|
|
42
|
+
defaultsDeep,
|
|
43
|
+
} from './helpers';
|
|
44
|
+
|
|
45
|
+
export interface LocaleConfig {
|
|
46
|
+
id: string;
|
|
47
|
+
firstDayOfWeek: number;
|
|
48
|
+
masks: any;
|
|
49
|
+
monthCacheSize: number;
|
|
50
|
+
pageCacheSize: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const DEFAULT_MONTH_CACHE_SIZE = 12;
|
|
54
|
+
const DEFAULT_PAGE_CACHE_SIZE = 5;
|
|
55
|
+
|
|
56
|
+
export function resolveConfig(
|
|
57
|
+
config: string | Partial<LocaleConfig> | undefined,
|
|
58
|
+
locales: any,
|
|
59
|
+
) {
|
|
60
|
+
// Get the detected locale string
|
|
61
|
+
const detLocale = new Intl.DateTimeFormat().resolvedOptions().locale;
|
|
62
|
+
// Resolve the locale id
|
|
63
|
+
let id;
|
|
64
|
+
if (isString(config)) {
|
|
65
|
+
id = config;
|
|
66
|
+
} else if (has(config, 'id')) {
|
|
67
|
+
id = config!.id;
|
|
68
|
+
}
|
|
69
|
+
id = (id || detLocale).toLowerCase();
|
|
70
|
+
const localeKeys = Object.keys(locales);
|
|
71
|
+
const validKey = (k: string) => localeKeys.find(lk => lk.toLowerCase() === k);
|
|
72
|
+
id = validKey(id) || validKey(id.substring(0, 2)) || detLocale;
|
|
73
|
+
// Add fallback and spread default locale to prevent repetitive update loops
|
|
74
|
+
const defLocale: LocaleConfig = {
|
|
75
|
+
...locales['en-IE'],
|
|
76
|
+
...locales[id],
|
|
77
|
+
id,
|
|
78
|
+
monthCacheSize: DEFAULT_MONTH_CACHE_SIZE,
|
|
79
|
+
pageCacheSize: DEFAULT_PAGE_CACHE_SIZE,
|
|
80
|
+
};
|
|
81
|
+
// Assign or merge defaults with provided config
|
|
82
|
+
const result: LocaleConfig = isObject(config)
|
|
83
|
+
? defaultsDeep(config, defLocale)
|
|
84
|
+
: defLocale;
|
|
85
|
+
// Return resolved config
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export default class Locale {
|
|
90
|
+
id: any;
|
|
91
|
+
daysInWeek: number;
|
|
92
|
+
firstDayOfWeek: DayOfWeek;
|
|
93
|
+
masks: any;
|
|
94
|
+
timezone: string | undefined;
|
|
95
|
+
hourLabels: string[];
|
|
96
|
+
dayNames: string[];
|
|
97
|
+
dayNamesShort: string[];
|
|
98
|
+
dayNamesShorter: string[];
|
|
99
|
+
dayNamesNarrow: string[];
|
|
100
|
+
monthNames: string[];
|
|
101
|
+
monthNamesShort: string[];
|
|
102
|
+
relativeTimeNames: TimeNames;
|
|
103
|
+
amPm: [string, string] = ['am', 'pm'];
|
|
104
|
+
monthCache: Cache<MonthParts>;
|
|
105
|
+
pageCache: Cache<CachedPage>;
|
|
106
|
+
|
|
107
|
+
constructor(
|
|
108
|
+
config: Partial<LocaleConfig> | string | undefined = undefined,
|
|
109
|
+
timezone?: string,
|
|
110
|
+
) {
|
|
111
|
+
const { id, firstDayOfWeek, masks, monthCacheSize, pageCacheSize } =
|
|
112
|
+
resolveConfig(config, defaultLocales.value);
|
|
113
|
+
this.monthCache = new Cache(
|
|
114
|
+
monthCacheSize,
|
|
115
|
+
getMonthPartsKey,
|
|
116
|
+
getMonthParts,
|
|
117
|
+
);
|
|
118
|
+
this.pageCache = new Cache(pageCacheSize, getPageKey, getCachedPage);
|
|
119
|
+
this.id = id;
|
|
120
|
+
this.daysInWeek = daysInWeek;
|
|
121
|
+
this.firstDayOfWeek = clamp(firstDayOfWeek, 1, daysInWeek) as DayOfWeek;
|
|
122
|
+
this.masks = masks;
|
|
123
|
+
this.timezone = timezone || undefined;
|
|
124
|
+
this.hourLabels = this.getHourLabels();
|
|
125
|
+
this.dayNames = getDayNames('long', this.id);
|
|
126
|
+
this.dayNamesShort = getDayNames('short', this.id);
|
|
127
|
+
this.dayNamesShorter = this.dayNamesShort.map(s => s.substring(0, 2));
|
|
128
|
+
this.dayNamesNarrow = getDayNames('narrow', this.id);
|
|
129
|
+
this.monthNames = getMonthNames('long', this.id);
|
|
130
|
+
this.monthNamesShort = getMonthNames('short', this.id);
|
|
131
|
+
this.relativeTimeNames = getRelativeTimeNames(this.id);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
formatDate(date: Date, masks: string | string[]) {
|
|
135
|
+
return formatDate(date, masks, this);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
parseDate(dateString: string, mask: string | string[]) {
|
|
139
|
+
return parseDate(dateString, mask, this);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
toDate(
|
|
143
|
+
d: DateSource | Partial<SimpleDateParts>,
|
|
144
|
+
opts: Partial<DateOptions> = {},
|
|
145
|
+
): Date {
|
|
146
|
+
const nullDate = new Date(NaN);
|
|
147
|
+
let result = nullDate;
|
|
148
|
+
const { fillDate, mask, patch, rules } = opts;
|
|
149
|
+
if (isNumber(d)) {
|
|
150
|
+
opts.type = 'number';
|
|
151
|
+
result = new Date(+d);
|
|
152
|
+
} else if (isString(d)) {
|
|
153
|
+
opts.type = 'string';
|
|
154
|
+
result = d ? parseDate(d, mask || 'iso', this) : nullDate;
|
|
155
|
+
} else if (isDate(d)) {
|
|
156
|
+
opts.type = 'date';
|
|
157
|
+
result = new Date(d.getTime());
|
|
158
|
+
} else if (isDateParts(d)) {
|
|
159
|
+
opts.type = 'object';
|
|
160
|
+
result = this.getDateFromParts(d);
|
|
161
|
+
}
|
|
162
|
+
// Patch parts or apply rules if needed
|
|
163
|
+
if (result && (patch || rules)) {
|
|
164
|
+
let parts = this.getDateParts(result);
|
|
165
|
+
// Patch date parts
|
|
166
|
+
if (patch && fillDate != null) {
|
|
167
|
+
const fillParts = this.getDateParts(this.toDate(fillDate));
|
|
168
|
+
parts = this.getDateParts(
|
|
169
|
+
this.toDate({ ...fillParts, ...pick(parts, DatePatchKeys[patch]) }),
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
// Apply date part rules
|
|
173
|
+
if (rules) {
|
|
174
|
+
parts = applyRulesForDateParts(parts, rules);
|
|
175
|
+
}
|
|
176
|
+
result = this.getDateFromParts(parts);
|
|
177
|
+
}
|
|
178
|
+
return result || nullDate;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
toDateOrNull(
|
|
182
|
+
d: DateSource | Partial<SimpleDateParts>,
|
|
183
|
+
opts: Partial<DateOptions> = {},
|
|
184
|
+
): Date | null {
|
|
185
|
+
const dte = this.toDate(d, opts);
|
|
186
|
+
return isNaN(dte.getTime()) ? null : dte;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
fromDate(date: Date | null, { type, mask }: Partial<DateOptions> = {}) {
|
|
190
|
+
switch (type) {
|
|
191
|
+
case 'number':
|
|
192
|
+
return date ? date.getTime() : NaN;
|
|
193
|
+
case 'string':
|
|
194
|
+
return date ? this.formatDate(date, mask || 'iso') : '';
|
|
195
|
+
case 'object':
|
|
196
|
+
return date ? this.getDateParts(date) : null;
|
|
197
|
+
default:
|
|
198
|
+
return date ? new Date(date) : null;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
range(source: DateRangeSource) {
|
|
203
|
+
return DateRange.from(source, this);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
ranges(ranges: DateRangeSource | DateRangeSource[]) {
|
|
207
|
+
return DateRange.fromMany(ranges, this);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
getDateParts(date: Date) {
|
|
211
|
+
return getDateParts(date, this);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
getDateFromParts(parts: Partial<SimpleDateParts>) {
|
|
215
|
+
return getDateFromParts(parts, this.timezone);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
getDateFromParams(
|
|
219
|
+
year: number,
|
|
220
|
+
month: number,
|
|
221
|
+
day: number,
|
|
222
|
+
hours: number,
|
|
223
|
+
minutes: number,
|
|
224
|
+
seconds: number,
|
|
225
|
+
milliseconds: number,
|
|
226
|
+
) {
|
|
227
|
+
return this.getDateFromParts({
|
|
228
|
+
year,
|
|
229
|
+
month,
|
|
230
|
+
day,
|
|
231
|
+
hours,
|
|
232
|
+
minutes,
|
|
233
|
+
seconds,
|
|
234
|
+
milliseconds,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
getPage(config: PageConfig) {
|
|
239
|
+
const cachedPage = this.pageCache.getOrSet(config, this);
|
|
240
|
+
return getPage(config, cachedPage);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
getMonthParts(month: number, year: number) {
|
|
244
|
+
const { firstDayOfWeek } = this;
|
|
245
|
+
return this.monthCache.getOrSet(month, year, firstDayOfWeek);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
getThisMonthParts() {
|
|
249
|
+
const date = new Date();
|
|
250
|
+
return this.getMonthParts(
|
|
251
|
+
<MonthInYear>(date.getMonth() + 1),
|
|
252
|
+
date.getFullYear(),
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
getPrevMonthParts(month: number, year: number) {
|
|
257
|
+
if (month === 1) return this.getMonthParts(12, year - 1);
|
|
258
|
+
return this.getMonthParts(month - 1, year);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
getNextMonthParts(month: number, year: number) {
|
|
262
|
+
if (month === 12) return this.getMonthParts(1, year + 1);
|
|
263
|
+
return this.getMonthParts(month + 1, year);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
getHourLabels() {
|
|
267
|
+
return getHourDates().map(d => {
|
|
268
|
+
return this.formatDate(d, this.masks.hours);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
getDayId(date: Date) {
|
|
273
|
+
return this.formatDate(date, 'YYYY-MM-DD');
|
|
274
|
+
}
|
|
275
|
+
}
|