akar 1.16.0 → 1.19.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/dist/calendar/calendar-root.js +6 -5
- package/dist/calendar/calendar-root.js.map +1 -1
- package/dist/combobox/combobox-content-impl.js +2 -1
- package/dist/combobox/combobox-content-impl.js.map +1 -1
- package/dist/date/calendar.date.js +25 -11
- package/dist/date/calendar.date.js.map +1 -1
- package/dist/date/comparators.date.js +10 -2
- package/dist/date/comparators.date.js.map +1 -1
- package/dist/date/use-date-field.js +59 -20
- package/dist/date/use-date-field.js.map +1 -1
- package/dist/date-picker/date-picker-root.js +10 -8
- package/dist/date-picker/date-picker-root.js.map +1 -1
- package/dist/date-range-picker/date-range-picker-root.js +11 -9
- package/dist/date-range-picker/date-range-picker-root.js.map +1 -1
- package/dist/date.d.ts +2 -2
- package/dist/date.js +2 -2
- package/dist/focus-scope/focus-scope.js +2 -2
- package/dist/focus-scope/focus-scope.js.map +1 -1
- package/dist/focus-scope/stack.js +1 -4
- package/dist/focus-scope/stack.js.map +1 -1
- package/dist/index.d.ts +819 -820
- package/dist/index.d.ts.map +1 -1
- package/dist/index2.d.ts +9 -2
- package/dist/index2.d.ts.map +1 -1
- package/dist/range-calendar/range-calendar-cell-trigger.js +3 -1
- package/dist/range-calendar/range-calendar-cell-trigger.js.map +1 -1
- package/dist/range-calendar/range-calendar-grid.js +2 -1
- package/dist/range-calendar/range-calendar-grid.js.map +1 -1
- package/dist/range-calendar/range-calendar-root.js +23 -14
- package/dist/range-calendar/range-calendar-root.js.map +1 -1
- package/dist/range-calendar/use-range-calendar.js +16 -6
- package/dist/range-calendar/use-range-calendar.js.map +1 -1
- package/dist/shared/use-grace-area.js +1 -1
- package/dist/shared/use-grace-area.js.map +1 -1
- package/dist/time-field/time-field-input.js +3 -1
- package/dist/time-field/time-field-input.js.map +1 -1
- package/dist/time-field/time-field-root.js +26 -2
- package/dist/time-field/time-field-root.js.map +1 -1
- package/package.json +7 -6
- package/src/calendar/calendar-root.vue +12 -11
- package/src/calendar/use-calendar.ts +2 -2
- package/src/combobox/combobox-content-impl.vue +1 -0
- package/src/combobox/combobox-root.vue +1 -1
- package/src/date/calendar.date.ts +42 -18
- package/src/date/comparators.date.ts +11 -3
- package/src/date-picker/date-picker-anchor.vue +2 -2
- package/src/date-picker/date-picker-arrow.vue +2 -2
- package/src/date-picker/date-picker-close.vue +2 -2
- package/src/date-picker/date-picker-root.vue +11 -11
- package/src/date-picker/index.ts +71 -27
- package/src/date-range-picker/date-range-picker-root.vue +14 -15
- package/src/focus-scope/focus-scope.vue +2 -2
- package/src/index.ts +1 -0
- package/src/listbox/listbox-filter.vue +1 -1
- package/src/listbox/listbox-root.vue +1 -1
- package/src/range-calendar/range-calendar-cell-trigger.vue +4 -2
- package/src/range-calendar/range-calendar-grid.vue +1 -0
- package/src/range-calendar/range-calendar-root.vue +41 -36
- package/src/range-calendar/use-range-calendar.ts +10 -12
- package/src/shared/date/use-date-field.ts +108 -21
- package/src/shared/use-grace-area.ts +1 -1
- package/src/time-field/time-field-input.vue +7 -2
- package/src/time-field/time-field-root.vue +42 -3
- package/src/tree/tree-root.vue +2 -2
|
@@ -47,7 +47,7 @@ export type AComboboxRootEmits<T = AcceptableValue> = {
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
export interface AComboboxRootProps<T = AcceptableValue> extends Omit<AListboxRootProps<T>, 'orientation' | 'selectionBehavior'> {
|
|
50
|
-
/** The controlled open state of the Combobox. Can be binded with
|
|
50
|
+
/** The controlled open state of the Combobox. Can be binded with `v-model:open`. */
|
|
51
51
|
open?: boolean;
|
|
52
52
|
/** The open state of the combobox when it is initially rendered. <br> Use when you do not need to control its open state. */
|
|
53
53
|
defaultOpen?: boolean;
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
endOfYear,
|
|
8
8
|
getDayOfWeek,
|
|
9
9
|
startOfMonth,
|
|
10
|
+
startOfWeek,
|
|
10
11
|
startOfYear,
|
|
11
12
|
} from '@internationalized/date';
|
|
12
13
|
import { chunk } from '@vinicunca/perkakas';
|
|
@@ -14,6 +15,8 @@ import { getDaysInMonth, getLastFirstDayOfWeek, getNextLastDayOfWeek } from './c
|
|
|
14
15
|
|
|
15
16
|
export type WeekDayFormat = 'long' | 'narrow' | 'short';
|
|
16
17
|
|
|
18
|
+
export type WeekStartsOn = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
19
|
+
|
|
17
20
|
export interface CreateSelectProps {
|
|
18
21
|
/**
|
|
19
22
|
* The date object representing the date (usually the first day of the month/year).
|
|
@@ -30,7 +33,7 @@ export interface CreateMonthProps {
|
|
|
30
33
|
/**
|
|
31
34
|
* The day of the week to start the calendar on (0 for Sunday, 1 for Monday, etc.).
|
|
32
35
|
*/
|
|
33
|
-
weekStartsOn:
|
|
36
|
+
weekStartsOn: WeekStartsOn;
|
|
34
37
|
|
|
35
38
|
/**
|
|
36
39
|
* Whether to always render 6 weeks in the calendar, even if the month doesn't
|
|
@@ -104,7 +107,6 @@ export function createMonth(props: CreateMonthProps): DateGrid<DateValue> {
|
|
|
104
107
|
|
|
105
108
|
const allDays = lastMonthDays.concat(datesArray, nextMonthDays);
|
|
106
109
|
|
|
107
|
-
// @ts-expect-error FIXME: we need to investigate further for this type.
|
|
108
110
|
const weeks = chunk(allDays, 7);
|
|
109
111
|
|
|
110
112
|
return {
|
|
@@ -251,24 +253,46 @@ export function createDateRange({ start, end }: DateRange): Array<DateValue> {
|
|
|
251
253
|
return dates;
|
|
252
254
|
}
|
|
253
255
|
|
|
256
|
+
/**
|
|
257
|
+
* It's better to use `getWeekStart` from `@internationalized/date`,
|
|
258
|
+
* but sadly it is not yet exported from the package.
|
|
259
|
+
* And the `Intl.Locale` API is not supported well enough yet.
|
|
260
|
+
*/
|
|
261
|
+
export function getWeekStartsOn(locale: string): WeekStartsOn {
|
|
262
|
+
// Jan 6, 2025 is a Monday (ISO day = 1)
|
|
263
|
+
const monday = new CalendarDate(2025, 1, 6);
|
|
264
|
+
const dayOfWeek = getDayOfWeek(monday, locale);
|
|
265
|
+
// dayOfWeek tells us Monday's position in the locale's week (0-indexed)
|
|
266
|
+
// If Monday is position 0 → week starts Monday (1)
|
|
267
|
+
// If Monday is position 1 → week starts Sunday (0)
|
|
268
|
+
return (1 - dayOfWeek + 7) % 7 as WeekStartsOn;
|
|
269
|
+
}
|
|
270
|
+
|
|
254
271
|
/**
|
|
255
272
|
* Returns the locale-specific week number
|
|
256
273
|
*/
|
|
257
274
|
export function getWeekNumber(date: DateValue, locale: string = 'en-US', firstDayOfWeek?: DayOfWeek): number {
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
275
|
+
const jan1 = new CalendarDate(date.year, 1, 1);
|
|
276
|
+
|
|
277
|
+
// Detect ISO locale by comparing JS day of week with locale day of week
|
|
278
|
+
const usesISOWeek = jan1.toDate('UTC').getUTCDay() !== getDayOfWeek(jan1, locale);
|
|
279
|
+
const weekStartsOn = firstDayOfWeek ?? (usesISOWeek ? 'mon' : 'sun');
|
|
280
|
+
const firstWeekContainsDate = usesISOWeek ? 4 : 1;
|
|
281
|
+
|
|
282
|
+
// Find the "deciding day" - its year determines which year's week numbering to use
|
|
283
|
+
const dayOfWeek = getDayOfWeek(date, locale, weekStartsOn);
|
|
284
|
+
const decidingDay = date.add({ days: 7 - firstWeekContainsDate - dayOfWeek });
|
|
285
|
+
const weekYear = decidingDay.year;
|
|
286
|
+
|
|
287
|
+
// Calculate week number from week 1 start
|
|
288
|
+
const week1Ref = new CalendarDate(weekYear, 1, firstWeekContainsDate);
|
|
289
|
+
const week1Start = startOfWeek(week1Ref, locale, weekStartsOn);
|
|
290
|
+
const currentWeekStart = startOfWeek(date, locale, weekStartsOn);
|
|
291
|
+
|
|
292
|
+
const MS_PER_WEEK = 7 * 24 * 60 * 60 * 1000;
|
|
293
|
+
const daysDiff = Math.round(
|
|
294
|
+
(currentWeekStart.toDate('UTC').getTime() - week1Start.toDate('UTC').getTime())
|
|
295
|
+
/ MS_PER_WEEK,
|
|
296
|
+
);
|
|
297
|
+
return daysDiff + 1;
|
|
274
298
|
}
|
|
@@ -2,7 +2,6 @@ import type { DateValue } from '@internationalized/date';
|
|
|
2
2
|
import type { DateMatcher } from './types.date';
|
|
3
3
|
import {
|
|
4
4
|
CalendarDateTime,
|
|
5
|
-
|
|
6
5
|
getDayOfWeek,
|
|
7
6
|
getLocalTimeZone,
|
|
8
7
|
parseDate,
|
|
@@ -175,7 +174,11 @@ export function getLastFirstDayOfWeek<T extends DateValue = DateValue>(
|
|
|
175
174
|
{ date, firstDayOfWeek, locale }:
|
|
176
175
|
DayOfWeekParams<T>,
|
|
177
176
|
): T {
|
|
178
|
-
|
|
177
|
+
/**
|
|
178
|
+
* "firstDayOfWeek" is fixed to 0(Sunday) to avoid confusion regarding locales.
|
|
179
|
+
* This also aligns with other date libraries, e.g., date-fns.
|
|
180
|
+
*/
|
|
181
|
+
const day = getDayOfWeek(date, locale, 'sun');
|
|
179
182
|
|
|
180
183
|
if (firstDayOfWeek > day) {
|
|
181
184
|
return date.subtract({ days: day + 7 - firstDayOfWeek }) as T;
|
|
@@ -192,7 +195,12 @@ export function getNextLastDayOfWeek<T extends DateValue = DateValue>(
|
|
|
192
195
|
{ date, firstDayOfWeek, locale }:
|
|
193
196
|
DayOfWeekParams<T>,
|
|
194
197
|
): T {
|
|
195
|
-
|
|
198
|
+
/**
|
|
199
|
+
* "firstDayOfWeek" is fixed to 0(Sunday) to avoid confusion regarding locales.
|
|
200
|
+
* This also aligns with other date libraries, e.g., date-fns.
|
|
201
|
+
*/
|
|
202
|
+
const day = getDayOfWeek(date, locale, 'sun');
|
|
203
|
+
|
|
196
204
|
const lastDayOfWeek = firstDayOfWeek === 0 ? 6 : firstDayOfWeek - 1;
|
|
197
205
|
|
|
198
206
|
if (day === lastDayOfWeek) {
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import type { APopoverAnchorProps } from '../popover';
|
|
3
3
|
import { APopoverAnchor } from '../popover';
|
|
4
4
|
|
|
5
|
-
export interface
|
|
5
|
+
export interface ADatePickerAnchorProps extends APopoverAnchorProps {}
|
|
6
6
|
</script>
|
|
7
7
|
|
|
8
8
|
<script setup lang="ts">
|
|
9
|
-
const props = defineProps<
|
|
9
|
+
const props = defineProps<ADatePickerAnchorProps>();
|
|
10
10
|
</script>
|
|
11
11
|
|
|
12
12
|
<template>
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import type { APopoverArrowProps } from '../popover';
|
|
3
3
|
import { APopoverArrow } from '../popover';
|
|
4
4
|
|
|
5
|
-
export interface
|
|
5
|
+
export interface ADatePickerArrowProps extends APopoverArrowProps {}
|
|
6
6
|
</script>
|
|
7
7
|
|
|
8
8
|
<script setup lang="ts">
|
|
9
|
-
const props = defineProps<
|
|
9
|
+
const props = defineProps<ADatePickerArrowProps>();
|
|
10
10
|
</script>
|
|
11
11
|
|
|
12
12
|
<template>
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import type { APopoverCloseProps } from '../popover';
|
|
3
3
|
import { APopoverClose } from '../popover';
|
|
4
4
|
|
|
5
|
-
export interface
|
|
5
|
+
export interface ADatePickerCloseProps extends APopoverCloseProps {}
|
|
6
6
|
</script>
|
|
7
7
|
|
|
8
8
|
<script setup lang="ts">
|
|
9
|
-
const props = defineProps<
|
|
9
|
+
const props = defineProps<ADatePickerCloseProps>();
|
|
10
10
|
</script>
|
|
11
11
|
|
|
12
12
|
<template>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { DateValue } from '@internationalized/date';
|
|
3
|
-
|
|
4
3
|
import type { Ref } from 'vue';
|
|
5
4
|
import type { ACalendarRootProps, ADateFieldRoot, ADateFieldRootProps, APopoverRootEmits, APopoverRootProps } from '..';
|
|
6
|
-
import type { DateMatcher, WeekDayFormat } from '../date';
|
|
5
|
+
import type { DateMatcher, WeekDayFormat, WeekStartsOn } from '../date';
|
|
7
6
|
import type { DateStep, Granularity, HourCycle } from '../shared/date';
|
|
8
7
|
import type { Direction } from '../shared/types';
|
|
9
|
-
import {
|
|
8
|
+
import { getWeekStartsOn } from '../date';
|
|
9
|
+
import { createContext } from '../shared';
|
|
10
10
|
|
|
11
11
|
type DatePickerRootContext = {
|
|
12
12
|
id: Ref<string | undefined>;
|
|
@@ -23,7 +23,7 @@ type DatePickerRootContext = {
|
|
|
23
23
|
placeholder: Ref<DateValue>;
|
|
24
24
|
pagedNavigation: Ref<boolean>;
|
|
25
25
|
preventDeselect: Ref<boolean>;
|
|
26
|
-
weekStartsOn: Ref<
|
|
26
|
+
weekStartsOn: Ref<WeekStartsOn>;
|
|
27
27
|
weekdayFormat: Ref<WeekDayFormat>;
|
|
28
28
|
fixedWeeks: Ref<boolean>;
|
|
29
29
|
numberOfMonths: Ref<number>;
|
|
@@ -46,7 +46,7 @@ export type ADatePickerRootProps = Omit<ADateFieldRootProps, 'as' | 'asChild'> &
|
|
|
46
46
|
closeOnSelect?: boolean;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
export type ADatePickerRootEmits = {
|
|
49
|
+
export type ADatePickerRootEmits = APopoverRootEmits & {
|
|
50
50
|
/** Event handler called whenever the model value changes */
|
|
51
51
|
'update:modelValue': [date: DateValue | undefined];
|
|
52
52
|
/** Event handler called whenever the placeholder value changes */
|
|
@@ -64,6 +64,7 @@ import { isSameDay } from '@internationalized/date';
|
|
|
64
64
|
import { useVModel } from '@vueuse/core';
|
|
65
65
|
import { computed, ref, toRefs, watch } from 'vue';
|
|
66
66
|
import { APopoverRoot } from '..';
|
|
67
|
+
import { useDirection, useLocale } from '../shared';
|
|
67
68
|
import { getDefaultDate } from '../shared/date';
|
|
68
69
|
|
|
69
70
|
defineOptions({
|
|
@@ -79,28 +80,25 @@ const props = withDefaults(
|
|
|
79
80
|
modal: false,
|
|
80
81
|
pagedNavigation: false,
|
|
81
82
|
preventDeselect: false,
|
|
82
|
-
weekStartsOn: 0,
|
|
83
83
|
weekdayFormat: 'narrow',
|
|
84
84
|
fixedWeeks: false,
|
|
85
85
|
numberOfMonths: 1,
|
|
86
86
|
disabled: false,
|
|
87
87
|
readonly: false,
|
|
88
88
|
placeholder: undefined,
|
|
89
|
-
locale: 'en',
|
|
90
89
|
isDateDisabled: undefined,
|
|
91
90
|
isDateUnavailable: undefined,
|
|
92
91
|
closeOnSelect: false,
|
|
93
92
|
},
|
|
94
93
|
);
|
|
95
94
|
|
|
96
|
-
const emits = defineEmits<ADatePickerRootEmits
|
|
95
|
+
const emits = defineEmits<ADatePickerRootEmits>();
|
|
97
96
|
|
|
98
97
|
const {
|
|
99
|
-
locale,
|
|
98
|
+
locale: propLocale,
|
|
100
99
|
disabled,
|
|
101
100
|
readonly,
|
|
102
101
|
pagedNavigation,
|
|
103
|
-
weekStartsOn,
|
|
104
102
|
weekdayFormat,
|
|
105
103
|
fixedWeeks,
|
|
106
104
|
numberOfMonths,
|
|
@@ -124,6 +122,8 @@ const {
|
|
|
124
122
|
} = toRefs(props);
|
|
125
123
|
|
|
126
124
|
const dir = useDirection(propDir);
|
|
125
|
+
const locale = useLocale(propLocale);
|
|
126
|
+
const weekStartsOn = computed(() => props.weekStartsOn ?? getWeekStartsOn(locale.value));
|
|
127
127
|
|
|
128
128
|
const modelValue = useVModel(props, 'modelValue', emits, {
|
|
129
129
|
defaultValue: defaultValue.value,
|
|
@@ -134,7 +134,7 @@ const defaultDate = computed(() => getDefaultDate({
|
|
|
134
134
|
defaultPlaceholder: props.placeholder,
|
|
135
135
|
granularity: props.granularity,
|
|
136
136
|
defaultValue: modelValue.value,
|
|
137
|
-
locale:
|
|
137
|
+
locale: locale.value,
|
|
138
138
|
}));
|
|
139
139
|
|
|
140
140
|
const placeholder = useVModel(props, 'placeholder', emits, {
|
package/src/date-picker/index.ts
CHANGED
|
@@ -1,30 +1,74 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
export {
|
|
2
|
+
default as ADatePickerAnchor,
|
|
3
|
+
type ADatePickerAnchorProps,
|
|
4
|
+
} from './date-picker-anchor.vue';
|
|
5
|
+
export {
|
|
6
|
+
default as ADatePickerArrow,
|
|
7
|
+
type ADatePickerArrowProps,
|
|
8
|
+
} from './date-picker-arrow.vue';
|
|
9
|
+
export {
|
|
10
|
+
default as ADatePickerCalendar,
|
|
11
|
+
} from './date-picker-calendar.vue';
|
|
12
|
+
export {
|
|
13
|
+
default as ADatePickerCellTrigger,
|
|
14
|
+
type ADatePickerCellTriggerProps,
|
|
15
|
+
} from './date-picker-cell-trigger.vue';
|
|
16
|
+
export {
|
|
17
|
+
default as ADatePickerCell,
|
|
18
|
+
type ADatePickerCellProps,
|
|
19
|
+
} from './date-picker-cell.vue';
|
|
20
|
+
export {
|
|
21
|
+
default as ADatePickerClose,
|
|
22
|
+
type ADatePickerCloseProps,
|
|
23
|
+
} from './date-picker-close.vue';
|
|
24
|
+
export {
|
|
25
|
+
default as ADatePickerContent,
|
|
26
|
+
type ADatePickerContentEmits,
|
|
27
|
+
type ADatePickerContentProps,
|
|
28
|
+
} from './date-picker-content.vue';
|
|
29
|
+
export {
|
|
30
|
+
default as ADatePickerField,
|
|
31
|
+
} from './date-picker-field.vue';
|
|
32
|
+
export {
|
|
33
|
+
default as ADatePickerGridBody,
|
|
34
|
+
type ADatePickerGridBodyProps,
|
|
35
|
+
} from './date-picker-grid-body.vue';
|
|
36
|
+
export {
|
|
37
|
+
default as ADatePickerGridHead,
|
|
38
|
+
type ADatePickerGridHeadProps,
|
|
39
|
+
} from './date-picker-grid-head.vue';
|
|
40
|
+
export {
|
|
41
|
+
default as ADatePickerGridRow,
|
|
42
|
+
type ADatePickerGridRowProps,
|
|
43
|
+
} from './date-picker-grid-row.vue';
|
|
44
|
+
export {
|
|
45
|
+
default as ADatePickerGrid,
|
|
46
|
+
type ADatePickerGridProps,
|
|
47
|
+
} from './date-picker-grid.vue';
|
|
48
|
+
export {
|
|
49
|
+
default as ADatePickerHeadCell,
|
|
50
|
+
type ADatePickerHeadCellProps,
|
|
51
|
+
} from './date-picker-head-cell.vue';
|
|
52
|
+
export {
|
|
53
|
+
default as ADatePickerHeader,
|
|
54
|
+
type ADatePickerHeaderProps,
|
|
55
|
+
} from './date-picker-header.vue';
|
|
56
|
+
export {
|
|
57
|
+
default as ADatePickerHeading,
|
|
58
|
+
type ADatePickerHeadingProps,
|
|
59
|
+
} from './date-picker-heading.vue';
|
|
60
|
+
export {
|
|
61
|
+
default as ADatePickerInput,
|
|
62
|
+
type ADatePickerInputProps,
|
|
63
|
+
} from './date-picker-input.vue';
|
|
64
|
+
export {
|
|
65
|
+
default as ADatePickerNext,
|
|
66
|
+
type ADatePickerNextProps,
|
|
67
|
+
} from './date-picker-next.vue';
|
|
68
|
+
export {
|
|
69
|
+
default as ADatePickerPrev,
|
|
70
|
+
type ADatePickerPrevProps,
|
|
71
|
+
} from './date-picker-prev.vue';
|
|
28
72
|
export {
|
|
29
73
|
default as ADatePickerRoot,
|
|
30
74
|
type ADatePickerRootEmits,
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { DateValue } from '@internationalized/date';
|
|
3
|
-
|
|
4
3
|
import type { Ref } from 'vue';
|
|
5
4
|
import type { ADateRangeFieldRoot, ADateRangeFieldRootProps, APopoverRootEmits, APopoverRootProps, ARangeCalendarRootProps } from '..';
|
|
6
|
-
import type { DateMatcher, WeekDayFormat } from '../date';
|
|
5
|
+
import type { DateMatcher, WeekDayFormat, WeekStartsOn } from '../date';
|
|
7
6
|
import type { DateRange, DateStep, Granularity, HourCycle } from '../shared/date';
|
|
8
|
-
|
|
9
7
|
import type { Direction } from '../shared/types';
|
|
10
|
-
import {
|
|
11
|
-
import { createContext, useDirection } from '../shared';
|
|
12
|
-
import { getDefaultDate } from '../shared/date';
|
|
8
|
+
import { createContext } from '../shared';
|
|
13
9
|
|
|
14
10
|
type DateRangePickerRootContext = {
|
|
15
11
|
id: Ref<string | undefined>;
|
|
@@ -26,7 +22,7 @@ type DateRangePickerRootContext = {
|
|
|
26
22
|
placeholder: Ref<DateValue>;
|
|
27
23
|
pagedNavigation: Ref<boolean>;
|
|
28
24
|
preventDeselect: Ref<boolean>;
|
|
29
|
-
weekStartsOn: Ref<
|
|
25
|
+
weekStartsOn: Ref<WeekStartsOn>;
|
|
30
26
|
weekdayFormat: Ref<WeekDayFormat>;
|
|
31
27
|
fixedWeeks: Ref<boolean>;
|
|
32
28
|
numberOfMonths: Ref<number>;
|
|
@@ -54,7 +50,7 @@ export type ADateRangePickerRootProps = Omit<ADateRangeFieldRootProps, 'as' | 'a
|
|
|
54
50
|
closeOnSelect?: boolean;
|
|
55
51
|
};
|
|
56
52
|
|
|
57
|
-
export type ADateRangePickerRootEmits = {
|
|
53
|
+
export type ADateRangePickerRootEmits = APopoverRootEmits & {
|
|
58
54
|
/** Event handler called whenever the model value changes */
|
|
59
55
|
'update:modelValue': [date: DateRange];
|
|
60
56
|
/** Event handler called whenever the placeholder value changes */
|
|
@@ -71,7 +67,11 @@ export const [
|
|
|
71
67
|
|
|
72
68
|
<script setup lang="ts">
|
|
73
69
|
import { useVModel } from '@vueuse/core';
|
|
74
|
-
import { ref, toRefs, watch } from 'vue';
|
|
70
|
+
import { computed, ref, toRefs, watch } from 'vue';
|
|
71
|
+
import { APopoverRoot } from '..';
|
|
72
|
+
import { getWeekStartsOn } from '../date';
|
|
73
|
+
import { useDirection, useLocale } from '../shared';
|
|
74
|
+
import { getDefaultDate } from '../shared/date';
|
|
75
75
|
|
|
76
76
|
defineOptions({
|
|
77
77
|
inheritAttrs: false,
|
|
@@ -86,14 +86,12 @@ const props = withDefaults(
|
|
|
86
86
|
modal: false,
|
|
87
87
|
pagedNavigation: false,
|
|
88
88
|
preventDeselect: false,
|
|
89
|
-
weekStartsOn: 0,
|
|
90
89
|
weekdayFormat: 'narrow',
|
|
91
90
|
fixedWeeks: false,
|
|
92
91
|
numberOfMonths: 1,
|
|
93
92
|
disabled: false,
|
|
94
93
|
readonly: false,
|
|
95
94
|
placeholder: undefined,
|
|
96
|
-
locale: 'en',
|
|
97
95
|
isDateDisabled: undefined,
|
|
98
96
|
isDateUnavailable: undefined,
|
|
99
97
|
isDateHighlightable: undefined,
|
|
@@ -103,14 +101,13 @@ const props = withDefaults(
|
|
|
103
101
|
},
|
|
104
102
|
);
|
|
105
103
|
|
|
106
|
-
const emits = defineEmits<ADateRangePickerRootEmits
|
|
104
|
+
const emits = defineEmits<ADateRangePickerRootEmits>();
|
|
107
105
|
|
|
108
106
|
const {
|
|
109
|
-
locale,
|
|
107
|
+
locale: propLocale,
|
|
110
108
|
disabled,
|
|
111
109
|
readonly,
|
|
112
110
|
pagedNavigation,
|
|
113
|
-
weekStartsOn,
|
|
114
111
|
weekdayFormat,
|
|
115
112
|
fixedWeeks,
|
|
116
113
|
numberOfMonths,
|
|
@@ -137,6 +134,8 @@ const {
|
|
|
137
134
|
} = toRefs(props);
|
|
138
135
|
|
|
139
136
|
const dir = useDirection(propsDir);
|
|
137
|
+
const locale = useLocale(propLocale);
|
|
138
|
+
const weekStartsOn = computed(() => props.weekStartsOn ?? getWeekStartsOn(locale.value));
|
|
140
139
|
|
|
141
140
|
const modelValue = useVModel(props, 'modelValue', emits, {
|
|
142
141
|
defaultValue: props.defaultValue ?? { start: undefined, end: undefined },
|
|
@@ -147,7 +146,7 @@ const defaultDate = getDefaultDate({
|
|
|
147
146
|
defaultPlaceholder: props.placeholder,
|
|
148
147
|
granularity: props.granularity,
|
|
149
148
|
defaultValue: modelValue.value?.start,
|
|
150
|
-
locale:
|
|
149
|
+
locale: locale.value,
|
|
151
150
|
});
|
|
152
151
|
|
|
153
152
|
const placeholder = useVModel(props, 'placeholder', emits, {
|
|
@@ -38,7 +38,7 @@ import { isClient } from '@vueuse/shared';
|
|
|
38
38
|
import { nextTick, reactive, ref, watchEffect } from 'vue';
|
|
39
39
|
import { APrimitive } from '../primitive';
|
|
40
40
|
import { getActiveElement, useForwardExpose } from '../shared';
|
|
41
|
-
import { createFocusScopesStack
|
|
41
|
+
import { createFocusScopesStack } from './stack';
|
|
42
42
|
import {
|
|
43
43
|
AUTOFOCUS_ON_MOUNT,
|
|
44
44
|
AUTOFOCUS_ON_UNMOUNT,
|
|
@@ -162,7 +162,7 @@ watchEffect(async (cleanupFn) => {
|
|
|
162
162
|
container.dispatchEvent(mountEvent);
|
|
163
163
|
|
|
164
164
|
if (!mountEvent.defaultPrevented) {
|
|
165
|
-
focusFirst(
|
|
165
|
+
focusFirst(getTabbableCandidates(container), {
|
|
166
166
|
select: true,
|
|
167
167
|
});
|
|
168
168
|
if (getActiveElement() === previouslyFocusedElement) {
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from './date-picker';
|
|
|
13
13
|
export * from './date-range-field';
|
|
14
14
|
export * from './date-range-picker';
|
|
15
15
|
export * from './dialog';
|
|
16
|
+
export { type FocusOutsideEvent, type PointerDownOutsideEvent } from './dismissable-layer';
|
|
16
17
|
export * from './drawer';
|
|
17
18
|
export * from './dropdown-menu';
|
|
18
19
|
export * from './editable';
|
|
@@ -3,7 +3,7 @@ import type { APrimitiveProps } from '../primitive';
|
|
|
3
3
|
import { injectAListboxRootContext } from './listbox-root.vue';
|
|
4
4
|
|
|
5
5
|
export interface AListboxFilterProps extends APrimitiveProps {
|
|
6
|
-
/** The controlled value of the filter. Can be binded with
|
|
6
|
+
/** The controlled value of the filter. Can be binded with v-model. */
|
|
7
7
|
modelValue?: string;
|
|
8
8
|
/** Focus on element when mounted. */
|
|
9
9
|
autoFocus?: boolean;
|
|
@@ -43,7 +43,7 @@ export const [
|
|
|
43
43
|
] = createContext<ListboxRootContext<AcceptableValue>>('AListboxRoot');
|
|
44
44
|
|
|
45
45
|
export interface AListboxRootProps<T = AcceptableValue> extends APrimitiveProps, FormFieldProps {
|
|
46
|
-
/** The controlled value of the listbox. Can be binded with
|
|
46
|
+
/** The controlled value of the listbox. Can be binded with `v-model`. */
|
|
47
47
|
modelValue?: T | Array<T>;
|
|
48
48
|
/** The value of the listbox when initially rendered. Use when you do not need to control the state of the Listbox */
|
|
49
49
|
defaultValue?: T | Array<T>;
|
|
@@ -118,22 +118,24 @@ function changeDate(event: KeyboardEvent | MouseEvent, date: DateValue) {
|
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
rootContext.lastPressedDateValue.value = date.copy();
|
|
122
|
-
|
|
123
121
|
if (rootContext.startValue.value && rootContext.highlightedRange.value === null) {
|
|
124
122
|
if (isSameDay(date, rootContext.startValue.value) && !rootContext.preventDeselect.value && !rootContext.endValue.value) {
|
|
125
123
|
rootContext.startValue.value = undefined;
|
|
126
124
|
rootContext.onPlaceholderChange(date);
|
|
125
|
+
rootContext.lastPressedDateValue.value = date.copy();
|
|
127
126
|
return;
|
|
128
127
|
} else if (!rootContext.endValue.value) {
|
|
129
128
|
event.preventDefault();
|
|
130
129
|
if (rootContext.lastPressedDateValue.value && isSameDay(rootContext.lastPressedDateValue.value, date)) {
|
|
131
130
|
rootContext.startValue.value = date.copy();
|
|
132
131
|
}
|
|
132
|
+
rootContext.lastPressedDateValue.value = date.copy();
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
+
rootContext.lastPressedDateValue.value = date.copy();
|
|
138
|
+
|
|
137
139
|
if (
|
|
138
140
|
rootContext.startValue.value
|
|
139
141
|
&& rootContext.endValue.value
|
|
@@ -26,6 +26,7 @@ const readonly = computed(() => rootContext.readonly.value ? true : undefined);
|
|
|
26
26
|
:aria-disabled="disabled"
|
|
27
27
|
:data-readonly="readonly && ''"
|
|
28
28
|
:data-disabled="disabled && ''"
|
|
29
|
+
@mouseleave="rootContext.focusedValue.value = undefined"
|
|
29
30
|
>
|
|
30
31
|
<slot />
|
|
31
32
|
</APrimitive>
|