akar 1.16.0 → 1.18.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 +799 -800
- 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-root.js +6 -5
- package/dist/range-calendar/range-calendar-root.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-root.vue +14 -14
- package/src/shared/date/use-date-field.ts +104 -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
|
@@ -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>;
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { DateValue } from '@internationalized/date';
|
|
3
3
|
import type { Ref } from 'vue';
|
|
4
|
-
import type { DateGrid, DateMatcher, WeekDayFormat } from '../date';
|
|
4
|
+
import type { DateGrid, DateMatcher, WeekDayFormat, WeekStartsOn } from '../date';
|
|
5
5
|
import type { APrimitiveProps } from '../primitive';
|
|
6
6
|
import type { UseDateFormatter } from '../shared';
|
|
7
7
|
import type { DateRange } from '../shared/date';
|
|
8
8
|
import type { Direction } from '../shared/types';
|
|
9
|
-
import {
|
|
10
|
-
import { KEY_CODES } from '@vinicunca/perkakas';
|
|
11
|
-
import { useCalendar } from '../calendar/use-calendar';
|
|
12
|
-
import { isDateBefore } from '../date';
|
|
13
|
-
import { createContext, useDirection, useLocale } from '../shared';
|
|
14
|
-
import { getDefaultDate, handleCalendarInitialFocus } from '../shared/date';
|
|
15
|
-
import { useRangeCalendarState } from './use-range-calendar';
|
|
9
|
+
import { createContext } from '../shared';
|
|
16
10
|
|
|
17
11
|
type RangeCalendarRootContext = {
|
|
18
12
|
modelValue: Ref<DateRange>;
|
|
@@ -24,7 +18,7 @@ type RangeCalendarRootContext = {
|
|
|
24
18
|
preventDeselect: Ref<boolean>;
|
|
25
19
|
grid: Ref<Array<DateGrid<DateValue>>>;
|
|
26
20
|
weekDays: Ref<Array<string>>;
|
|
27
|
-
weekStartsOn: Ref<
|
|
21
|
+
weekStartsOn: Ref<WeekStartsOn>;
|
|
28
22
|
weekdayFormat: Ref<WeekDayFormat>;
|
|
29
23
|
fixedWeeks: Ref<boolean>;
|
|
30
24
|
numberOfMonths: Ref<number>;
|
|
@@ -84,7 +78,7 @@ export interface ARangeCalendarRootProps extends APrimitiveProps {
|
|
|
84
78
|
/** The maximum number of days that can be selected in a range */
|
|
85
79
|
maximumDays?: number;
|
|
86
80
|
/** The day of the week to start the calendar on */
|
|
87
|
-
weekStartsOn?:
|
|
81
|
+
weekStartsOn?: WeekStartsOn;
|
|
88
82
|
/** The format to use for the weekday strings provided via the weekdays slot prop */
|
|
89
83
|
weekdayFormat?: WeekDayFormat;
|
|
90
84
|
/** The accessible label for the calendar */
|
|
@@ -141,9 +135,16 @@ export const [
|
|
|
141
135
|
</script>
|
|
142
136
|
|
|
143
137
|
<script setup lang="ts">
|
|
138
|
+
import { isEqualDay } from '@internationalized/date';
|
|
139
|
+
import { KEY_CODES } from '@vinicunca/perkakas';
|
|
144
140
|
import { useEventListener, useVModel } from '@vueuse/core';
|
|
145
|
-
import { onMounted, ref, toRefs, watch } from 'vue';
|
|
141
|
+
import { computed, onMounted, ref, toRefs, watch } from 'vue';
|
|
142
|
+
import { useCalendar } from '../calendar/use-calendar';
|
|
143
|
+
import { getWeekStartsOn, isDateBefore } from '../date';
|
|
146
144
|
import { APrimitive, usePrimitiveElement } from '../primitive';
|
|
145
|
+
import { useDirection, useLocale } from '../shared';
|
|
146
|
+
import { getDefaultDate, handleCalendarInitialFocus } from '../shared/date';
|
|
147
|
+
import { useRangeCalendarState } from './use-range-calendar';
|
|
147
148
|
|
|
148
149
|
const props = withDefaults(
|
|
149
150
|
defineProps<ARangeCalendarRootProps>(),
|
|
@@ -152,7 +153,6 @@ const props = withDefaults(
|
|
|
152
153
|
as: 'div',
|
|
153
154
|
pagedNavigation: false,
|
|
154
155
|
preventDeselect: false,
|
|
155
|
-
weekStartsOn: 0,
|
|
156
156
|
weekdayFormat: 'narrow',
|
|
157
157
|
fixedWeeks: false,
|
|
158
158
|
numberOfMonths: 1,
|
|
@@ -179,7 +179,7 @@ defineSlots<{
|
|
|
179
179
|
/** The days of the week */
|
|
180
180
|
weekDays: Array<string>;
|
|
181
181
|
/** The start of the week */
|
|
182
|
-
weekStartsOn:
|
|
182
|
+
weekStartsOn: WeekStartsOn;
|
|
183
183
|
/** The calendar locale */
|
|
184
184
|
locale: string;
|
|
185
185
|
/** Whether or not to always display 6 weeks in the calendar */
|
|
@@ -194,7 +194,6 @@ const {
|
|
|
194
194
|
readonly,
|
|
195
195
|
initialFocus,
|
|
196
196
|
pagedNavigation,
|
|
197
|
-
weekStartsOn,
|
|
198
197
|
weekdayFormat,
|
|
199
198
|
fixedWeeks,
|
|
200
199
|
numberOfMonths,
|
|
@@ -221,6 +220,7 @@ const {
|
|
|
221
220
|
} = usePrimitiveElement();
|
|
222
221
|
const dir = useDirection(propDir);
|
|
223
222
|
const locale = useLocale(propLocale);
|
|
223
|
+
const weekStartsOn = computed(() => props.weekStartsOn ?? getWeekStartsOn(locale.value));
|
|
224
224
|
|
|
225
225
|
const lastPressedDateValue = ref() as Ref<DateValue | undefined>;
|
|
226
226
|
const focusedValue = ref() as Ref<DateValue | undefined>;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import type { CalendarDateTime,
|
|
1
|
+
import type { CalendarDateTime, DateFields, DateValue, TimeFields } from '@internationalized/date';
|
|
2
2
|
import type { Ref } from 'vue';
|
|
3
3
|
import type { UseDateFormatter } from '../../shared';
|
|
4
4
|
import type { AnyExceptLiteral, DateStep, HourCycle, SegmentPart, SegmentValueObj } from './types';
|
|
5
|
+
import {
|
|
6
|
+
DateFormatter,
|
|
7
|
+
} from '@internationalized/date';
|
|
5
8
|
import { isIncludedIn, KEY_CODES } from '@vinicunca/perkakas';
|
|
6
9
|
import { computed } from 'vue';
|
|
7
10
|
import { getDaysInMonth, toDate } from '../../date';
|
|
11
|
+
import { snapValueToStep } from '../../shared';
|
|
8
12
|
import { isAcceptableSegmentKey, isNumberString, isSegmentNavigationKey } from './segment';
|
|
9
13
|
|
|
10
14
|
interface MinuteSecondIncrementProps {
|
|
@@ -19,7 +23,6 @@ interface DateTimeValueIncrementation {
|
|
|
19
23
|
part: keyof Omit<DateFields, 'era'> | keyof TimeFields;
|
|
20
24
|
dateRef: DateValue;
|
|
21
25
|
prevValue: null | number;
|
|
22
|
-
hourCycle?: HourCycle;
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
interface SegmentAttrProps {
|
|
@@ -299,6 +302,7 @@ export interface UseDateFieldProps {
|
|
|
299
302
|
placeholder: Ref<DateValue>;
|
|
300
303
|
hourCycle: HourCycle;
|
|
301
304
|
step: Ref<DateStep>;
|
|
305
|
+
stepSnapping?: Ref<boolean>;
|
|
302
306
|
formatter: UseDateFormatter;
|
|
303
307
|
segmentValues: Ref<SegmentValueObj>;
|
|
304
308
|
disabled: Ref<boolean>;
|
|
@@ -339,7 +343,7 @@ export function useDateField(props: UseDateFieldProps) {
|
|
|
339
343
|
return Number.parseInt(str.slice(0, -1));
|
|
340
344
|
}
|
|
341
345
|
|
|
342
|
-
function dateTimeValueIncrementation({ event, part, dateRef, prevValue
|
|
346
|
+
function dateTimeValueIncrementation({ event, part, dateRef, prevValue }: DateTimeValueIncrementation): number {
|
|
343
347
|
const step = props.step.value[part] ?? 1;
|
|
344
348
|
const sign = event.key === KEY_CODES.ARROW_UP ? step : -step;
|
|
345
349
|
|
|
@@ -348,7 +352,9 @@ export function useDateField(props: UseDateFieldProps) {
|
|
|
348
352
|
}
|
|
349
353
|
|
|
350
354
|
if (part === 'hour' && 'hour' in dateRef) {
|
|
351
|
-
|
|
355
|
+
// Don't pass hourCycle to cycle - internal representation is always 24-hour
|
|
356
|
+
// The hourCycle prop only affects display, not internal cycling
|
|
357
|
+
const cycleArgs: [keyof DateFields | keyof TimeFields, number] = [part, sign];
|
|
352
358
|
return dateRef.set({ [part as keyof DateValue]: prevValue }).cycle(...cycleArgs)[part];
|
|
353
359
|
}
|
|
354
360
|
|
|
@@ -528,8 +534,7 @@ export function useDateField(props: UseDateFieldProps) {
|
|
|
528
534
|
return { value: total, moveToNext };
|
|
529
535
|
}
|
|
530
536
|
|
|
531
|
-
function updateHour(num: number, prev: null | number) {
|
|
532
|
-
const max = 24;
|
|
537
|
+
function updateHour(max: number, num: number, prev: null | number) {
|
|
533
538
|
let moveToNext = false;
|
|
534
539
|
const maxStart = Math.floor(max / 10);
|
|
535
540
|
|
|
@@ -744,6 +749,11 @@ export function useDateField(props: UseDateFieldProps) {
|
|
|
744
749
|
}
|
|
745
750
|
}
|
|
746
751
|
|
|
752
|
+
function uses12HourFormat(locale: string): boolean {
|
|
753
|
+
const hourCycle = new DateFormatter(locale, { hour: 'numeric' }).resolvedOptions().hourCycle;
|
|
754
|
+
return hourCycle === 'h11' || hourCycle === 'h12';
|
|
755
|
+
}
|
|
756
|
+
|
|
747
757
|
function handleHourSegmentKeydown(event: KeyboardEvent) {
|
|
748
758
|
const dateRef = props.placeholder.value;
|
|
749
759
|
if (!isAcceptableSegmentKey(event.key) || isSegmentNavigationKey(event.key) || !('hour' in dateRef) || !('hour' in props.segmentValues.value)) {
|
|
@@ -752,17 +762,14 @@ export function useDateField(props: UseDateFieldProps) {
|
|
|
752
762
|
|
|
753
763
|
const prevValue = props.segmentValues.value.hour;
|
|
754
764
|
|
|
755
|
-
const hourCycle = props.hourCycle;
|
|
756
|
-
|
|
757
765
|
if (event.key === KEY_CODES.ARROW_UP || event.key === KEY_CODES.ARROW_DOWN) {
|
|
758
|
-
|
|
766
|
+
const newHour = dateTimeValueIncrementation({ event, part: 'hour', dateRef: props.placeholder.value, prevValue });
|
|
767
|
+
props.segmentValues.value.hour = newHour;
|
|
759
768
|
|
|
760
|
-
if ('dayPeriod' in props.segmentValues.value) {
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
props.segmentValues.value.dayPeriod = 'PM';
|
|
765
|
-
}
|
|
769
|
+
if ('dayPeriod' in props.segmentValues.value && newHour !== null) {
|
|
770
|
+
// Determine AM/PM based on internal 24-hour value
|
|
771
|
+
// Hour 0-11 = AM, Hour 12-23 = PM
|
|
772
|
+
props.segmentValues.value.dayPeriod = newHour >= 12 ? 'PM' : 'AM';
|
|
766
773
|
}
|
|
767
774
|
|
|
768
775
|
return;
|
|
@@ -770,15 +777,32 @@ export function useDateField(props: UseDateFieldProps) {
|
|
|
770
777
|
|
|
771
778
|
if (isNumberString(event.key)) {
|
|
772
779
|
const num = Number.parseInt(event.key);
|
|
773
|
-
const
|
|
780
|
+
const is12Hour = uses12HourFormat(props.formatter.getLocale());
|
|
781
|
+
const max = is12Hour ? 12 : 24;
|
|
782
|
+
|
|
783
|
+
let displayPrev = prevValue;
|
|
784
|
+
if (is12Hour && prevValue !== null) {
|
|
785
|
+
if (prevValue === 0) {
|
|
786
|
+
displayPrev = 12;
|
|
787
|
+
} else if (prevValue > 12) {
|
|
788
|
+
displayPrev = prevValue - 12;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
774
791
|
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
792
|
+
const { value, moveToNext } = updateHour(max, num, displayPrev);
|
|
793
|
+
|
|
794
|
+
// Convert display hour back to internal 24-hour format
|
|
795
|
+
let internalValue = value;
|
|
796
|
+
if (is12Hour && value !== null) {
|
|
797
|
+
const period = props.segmentValues.value.dayPeriod || 'AM';
|
|
798
|
+
if (value === 12) {
|
|
799
|
+
internalValue = period === 'AM' ? 0 : 12;
|
|
800
|
+
} else {
|
|
801
|
+
internalValue = period === 'PM' ? value + 12 : value;
|
|
802
|
+
}
|
|
779
803
|
}
|
|
780
804
|
|
|
781
|
-
props.segmentValues.value.hour =
|
|
805
|
+
props.segmentValues.value.hour = internalValue;
|
|
782
806
|
|
|
783
807
|
if (moveToNext) {
|
|
784
808
|
props.focusNext();
|
|
@@ -935,9 +959,68 @@ export function useDateField(props: UseDateFieldProps) {
|
|
|
935
959
|
}
|
|
936
960
|
}
|
|
937
961
|
|
|
962
|
+
function handleSegmentFocusOut() {
|
|
963
|
+
if (!props.stepSnapping?.value) {
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
if (
|
|
968
|
+
props.part === 'hour'
|
|
969
|
+
&& 'hour' in props.segmentValues.value
|
|
970
|
+
&& props.segmentValues.value.hour !== null
|
|
971
|
+
&& props.step.value.hour
|
|
972
|
+
&& props.step.value.hour > 1
|
|
973
|
+
) {
|
|
974
|
+
props.segmentValues.value.hour = snapValueToStep({
|
|
975
|
+
value: props.segmentValues.value.hour,
|
|
976
|
+
min: 0,
|
|
977
|
+
max: 23,
|
|
978
|
+
step: props.step.value.hour,
|
|
979
|
+
});
|
|
980
|
+
|
|
981
|
+
if ('dayPeriod' in props.segmentValues.value) {
|
|
982
|
+
if (props.segmentValues.value.hour < 12) {
|
|
983
|
+
props.segmentValues.value.dayPeriod = 'AM';
|
|
984
|
+
} else if (props.segmentValues.value.hour) {
|
|
985
|
+
props.segmentValues.value.dayPeriod = 'PM';
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
} else if (
|
|
989
|
+
props.part === 'minute'
|
|
990
|
+
&& 'minute' in props.segmentValues.value
|
|
991
|
+
&& props.segmentValues.value.minute !== null
|
|
992
|
+
&& props.step.value.minute
|
|
993
|
+
&& props.step.value.minute > 1) {
|
|
994
|
+
props.segmentValues.value.minute = snapValueToStep({
|
|
995
|
+
value: props.segmentValues.value.minute,
|
|
996
|
+
min: 0,
|
|
997
|
+
max: 59,
|
|
998
|
+
step: props.step.value.minute,
|
|
999
|
+
});
|
|
1000
|
+
} else if (
|
|
1001
|
+
props.part === 'second'
|
|
1002
|
+
&& 'second' in props.segmentValues.value
|
|
1003
|
+
&& props.segmentValues.value.second !== null
|
|
1004
|
+
&& props.step.value.second
|
|
1005
|
+
&& props.step.value.second > 1) {
|
|
1006
|
+
props.segmentValues.value.second = snapValueToStep({
|
|
1007
|
+
value: props.segmentValues.value.second,
|
|
1008
|
+
min: 0,
|
|
1009
|
+
max: 59,
|
|
1010
|
+
step: props.step.value.second,
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
if (Object.values(props.segmentValues.value).every((item) => item !== null)) {
|
|
1015
|
+
const dateRef = props.placeholder.value.set({ ...props.segmentValues.value as Record<AnyExceptLiteral, number> });
|
|
1016
|
+
props.modelValue.value = dateRef.copy();
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
|
|
938
1020
|
return {
|
|
939
1021
|
handleSegmentClick,
|
|
940
1022
|
handleSegmentKeydown,
|
|
1023
|
+
handleSegmentFocusOut,
|
|
941
1024
|
attributes,
|
|
942
1025
|
};
|
|
943
1026
|
}
|
|
@@ -38,7 +38,7 @@ export function useGraceArea(
|
|
|
38
38
|
point: exitPoint,
|
|
39
39
|
rect: currentTarget.getBoundingClientRect(),
|
|
40
40
|
});
|
|
41
|
-
const paddedExitPoints = getPaddedExitPoints(exitPoint, exitSide);
|
|
41
|
+
const paddedExitPoints = getPaddedExitPoints(exitPoint, exitSide, 1);
|
|
42
42
|
const hoverTargetPoints = getPointsFromRect(hoverTarget.getBoundingClientRect());
|
|
43
43
|
const graceArea = getHull([...paddedExitPoints, ...hoverTargetPoints]);
|
|
44
44
|
pointerGraceArea.value = graceArea;
|
|
@@ -23,6 +23,7 @@ const lastKeyZero = ref(false);
|
|
|
23
23
|
const {
|
|
24
24
|
handleSegmentClick,
|
|
25
25
|
handleSegmentKeydown,
|
|
26
|
+
handleSegmentFocusOut,
|
|
26
27
|
attributes,
|
|
27
28
|
} = useDateField({
|
|
28
29
|
hasLeftFocus,
|
|
@@ -30,6 +31,7 @@ const {
|
|
|
30
31
|
placeholder: rootContext.placeholder,
|
|
31
32
|
hourCycle: rootContext.hourCycle,
|
|
32
33
|
step: rootContext.step,
|
|
34
|
+
stepSnapping: rootContext.stepSnapping,
|
|
33
35
|
segmentValues: rootContext.segmentValues,
|
|
34
36
|
formatter: rootContext.formatter,
|
|
35
37
|
part: props.part,
|
|
@@ -59,9 +61,12 @@ const isInvalid = computed(() => rootContext.isInvalid.value);
|
|
|
59
61
|
v-on="part !== 'literal' ? {
|
|
60
62
|
mousedown: handleSegmentClick,
|
|
61
63
|
keydown: handleSegmentKeydown,
|
|
62
|
-
focusout: () => {
|
|
64
|
+
focusout: () => {
|
|
65
|
+
hasLeftFocus = true;
|
|
66
|
+
handleSegmentFocusOut();
|
|
67
|
+
},
|
|
63
68
|
focusin: (event: FocusEvent) => {
|
|
64
|
-
rootContext.setFocusedElement(event.target as HTMLElement)
|
|
69
|
+
rootContext.setFocusedElement(event.target as HTMLElement);
|
|
65
70
|
},
|
|
66
71
|
} : {}"
|
|
67
72
|
>
|