@rupe/v-datepicker 1.0.0-alpha.2 → 1.0.0-beta.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/components/Calendar/CalendarMonthYearOverlay.vue.d.ts +16 -17
- package/dist/components/Calendar/CalendarOverlayItem.vue.d.ts +82 -4
- package/dist/components/DatePicker/DatePickerMonthYearOverlay.vue.d.ts +2 -2
- package/dist/index.cjs +94 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +94 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/Calendar/CalendarMonthYearOverlay.vue +32 -8
- package/src/components/Calendar/CalendarOverlayItem.vue +92 -5
- package/src/components/Calendar/useCalendar.ts +3 -5
|
@@ -1,26 +1,25 @@
|
|
|
1
|
+
import { ComputedRef, DefineComponent, ComponentOptionsMixin, PublicProps, ComponentProvideOptions, Ref } from 'vue';
|
|
1
2
|
import { PrimitiveProps } from '../Primitive';
|
|
2
3
|
import { MonthNameDateValue } from './CalendarRoot.vue';
|
|
3
|
-
import { Ref, DefineComponent, ComponentOptionsMixin, PublicProps, ComponentProvideOptions } from 'vue';
|
|
4
4
|
export interface CalendarMonthYearOverlayProps extends PrimitiveProps {
|
|
5
5
|
type: "month" | "year";
|
|
6
|
+
itemsPerRow?: number;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
slots: {
|
|
10
|
-
default?(_: {
|
|
11
|
-
months: MonthNameDateValue[];
|
|
12
|
-
years: {
|
|
13
|
-
year: number;
|
|
14
|
-
}[];
|
|
15
|
-
state: Ref<false | "month" | "year", false | "month" | "year">;
|
|
16
|
-
}): any;
|
|
17
|
-
};
|
|
18
|
-
refs: {};
|
|
19
|
-
rootEl: any;
|
|
8
|
+
type CalendarMonthYearOverlayContext = {
|
|
9
|
+
itemsPerRow: ComputedRef<number>;
|
|
20
10
|
};
|
|
21
|
-
|
|
22
|
-
declare const
|
|
23
|
-
|
|
11
|
+
export declare const injectCalendarMonthYearOverlayContext: <T extends CalendarMonthYearOverlayContext | null | undefined = CalendarMonthYearOverlayContext>(fallback?: T | undefined) => T extends null ? CalendarMonthYearOverlayContext | null : CalendarMonthYearOverlayContext, provideCalendarMonthYearOverlayContext: (contextValue: CalendarMonthYearOverlayContext) => CalendarMonthYearOverlayContext;
|
|
12
|
+
declare const _default: __VLS_WithTemplateSlots< DefineComponent<CalendarMonthYearOverlayProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<CalendarMonthYearOverlayProps> & Readonly<{}>, {
|
|
13
|
+
itemsPerRow: number;
|
|
14
|
+
}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>, {
|
|
15
|
+
default?(_: {
|
|
16
|
+
months: MonthNameDateValue[][];
|
|
17
|
+
years: {
|
|
18
|
+
year: number;
|
|
19
|
+
}[][];
|
|
20
|
+
state: Ref<false | "month" | "year", false | "month" | "year">;
|
|
21
|
+
}): any;
|
|
22
|
+
}>;
|
|
24
23
|
export default _default;
|
|
25
24
|
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
26
25
|
new (): {
|
|
@@ -1,21 +1,99 @@
|
|
|
1
1
|
import { DateValue } from '@internationalized/date';
|
|
2
2
|
import { PrimitiveProps, AsTag } from '../Primitive';
|
|
3
|
-
import {
|
|
3
|
+
import { CreateComponentPublicInstanceWithMixins, ExtractPropTypes, PropType, Component, VNode, RendererNode, RendererElement, ComponentOptionsMixin, PublicProps, GlobalComponents, GlobalDirectives, ComponentProvideOptions, DefineComponent } from 'vue';
|
|
4
4
|
export interface CalendarOverlayItemProps extends PrimitiveProps {
|
|
5
|
-
date: DateValue
|
|
5
|
+
date: DateValue & {
|
|
6
|
+
monthName: string;
|
|
7
|
+
};
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
type: "month" | "year";
|
|
6
10
|
}
|
|
7
11
|
declare function __VLS_template(): {
|
|
8
12
|
attrs: Partial<{}>;
|
|
9
13
|
slots: {
|
|
10
14
|
default?(_: {}): any;
|
|
11
15
|
};
|
|
12
|
-
refs: {
|
|
16
|
+
refs: {
|
|
17
|
+
primitiveElement: CreateComponentPublicInstanceWithMixins<Readonly< ExtractPropTypes<{
|
|
18
|
+
asChild: {
|
|
19
|
+
type: BooleanConstructor;
|
|
20
|
+
default: boolean;
|
|
21
|
+
};
|
|
22
|
+
as: {
|
|
23
|
+
type: PropType< AsTag | Component>;
|
|
24
|
+
default: string;
|
|
25
|
+
};
|
|
26
|
+
}>> & Readonly<{}>, () => VNode<RendererNode, RendererElement, {
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
}>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, PublicProps, {
|
|
29
|
+
asChild: boolean;
|
|
30
|
+
as: AsTag | Component;
|
|
31
|
+
}, true, {}, {}, GlobalComponents, GlobalDirectives, string, {}, any, ComponentProvideOptions, {
|
|
32
|
+
P: {};
|
|
33
|
+
B: {};
|
|
34
|
+
D: {};
|
|
35
|
+
C: {};
|
|
36
|
+
M: {};
|
|
37
|
+
Defaults: {};
|
|
38
|
+
}, Readonly< ExtractPropTypes<{
|
|
39
|
+
asChild: {
|
|
40
|
+
type: BooleanConstructor;
|
|
41
|
+
default: boolean;
|
|
42
|
+
};
|
|
43
|
+
as: {
|
|
44
|
+
type: PropType< AsTag | Component>;
|
|
45
|
+
default: string;
|
|
46
|
+
};
|
|
47
|
+
}>> & Readonly<{}>, () => VNode<RendererNode, RendererElement, {
|
|
48
|
+
[key: string]: any;
|
|
49
|
+
}>, {}, {}, {}, {
|
|
50
|
+
asChild: boolean;
|
|
51
|
+
as: AsTag | Component;
|
|
52
|
+
}> | null;
|
|
53
|
+
};
|
|
13
54
|
rootEl: any;
|
|
14
55
|
};
|
|
15
56
|
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
16
57
|
declare const __VLS_component: DefineComponent<CalendarOverlayItemProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<CalendarOverlayItemProps> & Readonly<{}>, {
|
|
17
58
|
as: AsTag | Component;
|
|
18
|
-
}, {}, {}, {}, string, ComponentProvideOptions, false, {
|
|
59
|
+
}, {}, {}, {}, string, ComponentProvideOptions, false, {
|
|
60
|
+
primitiveElement: CreateComponentPublicInstanceWithMixins<Readonly< ExtractPropTypes<{
|
|
61
|
+
asChild: {
|
|
62
|
+
type: BooleanConstructor;
|
|
63
|
+
default: boolean;
|
|
64
|
+
};
|
|
65
|
+
as: {
|
|
66
|
+
type: PropType< AsTag | Component>;
|
|
67
|
+
default: string;
|
|
68
|
+
};
|
|
69
|
+
}>> & Readonly<{}>, () => VNode<RendererNode, RendererElement, {
|
|
70
|
+
[key: string]: any;
|
|
71
|
+
}>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, PublicProps, {
|
|
72
|
+
asChild: boolean;
|
|
73
|
+
as: AsTag | Component;
|
|
74
|
+
}, true, {}, {}, GlobalComponents, GlobalDirectives, string, {}, any, ComponentProvideOptions, {
|
|
75
|
+
P: {};
|
|
76
|
+
B: {};
|
|
77
|
+
D: {};
|
|
78
|
+
C: {};
|
|
79
|
+
M: {};
|
|
80
|
+
Defaults: {};
|
|
81
|
+
}, Readonly< ExtractPropTypes<{
|
|
82
|
+
asChild: {
|
|
83
|
+
type: BooleanConstructor;
|
|
84
|
+
default: boolean;
|
|
85
|
+
};
|
|
86
|
+
as: {
|
|
87
|
+
type: PropType< AsTag | Component>;
|
|
88
|
+
default: string;
|
|
89
|
+
};
|
|
90
|
+
}>> & Readonly<{}>, () => VNode<RendererNode, RendererElement, {
|
|
91
|
+
[key: string]: any;
|
|
92
|
+
}>, {}, {}, {}, {
|
|
93
|
+
asChild: boolean;
|
|
94
|
+
as: AsTag | Component;
|
|
95
|
+
}> | null;
|
|
96
|
+
}, any>;
|
|
19
97
|
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
20
98
|
export default _default;
|
|
21
99
|
type __VLS_WithTemplateSlots<T, S> = T & {
|
package/dist/index.cjs
CHANGED
|
@@ -24,6 +24,12 @@ function _interopNamespaceDefault(e) {
|
|
|
24
24
|
return Object.freeze(n);
|
|
25
25
|
}
|
|
26
26
|
const vue__namespace = /* @__PURE__ */ _interopNamespaceDefault(vue);
|
|
27
|
+
function chunk$1(arr, size) {
|
|
28
|
+
const result = [];
|
|
29
|
+
for (let i = 0; i < arr.length; i += size)
|
|
30
|
+
result.push(arr.slice(i, i + size));
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
27
33
|
function createContext(providerComponentName, contextName) {
|
|
28
34
|
const symbolDescription = typeof providerComponentName === "string" && !contextName ? `${providerComponentName}Context` : contextName;
|
|
29
35
|
const injectionKey = Symbol(symbolDescription);
|
|
@@ -4157,6 +4163,10 @@ const _sfc_main$r = /* @__PURE__ */ vue.defineComponent({
|
|
|
4157
4163
|
};
|
|
4158
4164
|
}
|
|
4159
4165
|
});
|
|
4166
|
+
const [
|
|
4167
|
+
injectCalendarMonthYearOverlayContext,
|
|
4168
|
+
provideCalendarMonthYearOverlayContext
|
|
4169
|
+
] = createContext("CalendarMonthYearOverlay");
|
|
4160
4170
|
const _sfc_main$q = /* @__PURE__ */ vue.defineComponent({
|
|
4161
4171
|
...{
|
|
4162
4172
|
inheritAttrs: false
|
|
@@ -4164,20 +4174,27 @@ const _sfc_main$q = /* @__PURE__ */ vue.defineComponent({
|
|
|
4164
4174
|
__name: "CalendarMonthYearOverlay",
|
|
4165
4175
|
props: {
|
|
4166
4176
|
type: {},
|
|
4177
|
+
itemsPerRow: { default: 4 },
|
|
4167
4178
|
asChild: { type: Boolean },
|
|
4168
4179
|
as: {}
|
|
4169
4180
|
},
|
|
4170
4181
|
setup(__props) {
|
|
4171
4182
|
const props = __props;
|
|
4183
|
+
const itemsPerRow = vue.computed(() => props.itemsPerRow);
|
|
4172
4184
|
const rootContext = injectCalendarRootContext();
|
|
4173
|
-
const months = vue.computed(
|
|
4174
|
-
|
|
4185
|
+
const months = vue.computed(
|
|
4186
|
+
() => chunk$1(rootContext.months.value, props.itemsPerRow)
|
|
4187
|
+
);
|
|
4188
|
+
const years = vue.computed(() => chunk$1(rootContext.years.value, props.itemsPerRow));
|
|
4175
4189
|
const isOpen = vue.computed(
|
|
4176
4190
|
() => rootContext.monthYearOverlayState.value === props.type
|
|
4177
4191
|
);
|
|
4178
4192
|
function onEscapeKeyDown() {
|
|
4179
4193
|
rootContext.monthYearOverlayState.value = false;
|
|
4180
4194
|
}
|
|
4195
|
+
provideCalendarMonthYearOverlayContext({
|
|
4196
|
+
itemsPerRow
|
|
4197
|
+
});
|
|
4181
4198
|
return (_ctx, _cache) => {
|
|
4182
4199
|
return isOpen.value ? (vue.openBlock(), vue.createBlock(_sfc_main$O, {
|
|
4183
4200
|
key: 0,
|
|
@@ -5143,6 +5160,7 @@ const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
|
|
|
5143
5160
|
__name: "DatePickerMonthYearOverlay",
|
|
5144
5161
|
props: {
|
|
5145
5162
|
type: {},
|
|
5163
|
+
itemsPerRow: {},
|
|
5146
5164
|
asChild: { type: Boolean },
|
|
5147
5165
|
as: {}
|
|
5148
5166
|
},
|
|
@@ -5165,25 +5183,93 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
|
|
|
5165
5183
|
__name: "CalendarOverlayItem",
|
|
5166
5184
|
props: {
|
|
5167
5185
|
date: {},
|
|
5186
|
+
disabled: { type: Boolean },
|
|
5187
|
+
type: {},
|
|
5168
5188
|
asChild: { type: Boolean },
|
|
5169
|
-
as: { default: "
|
|
5189
|
+
as: { default: "div" }
|
|
5170
5190
|
},
|
|
5171
5191
|
setup(__props) {
|
|
5172
5192
|
const props = __props;
|
|
5173
5193
|
const rootContext = injectCalendarRootContext();
|
|
5194
|
+
const years = vue.computed(() => rootContext.years.value);
|
|
5195
|
+
const maxValue = vue.computed(
|
|
5196
|
+
() => props.type === "month" ? 12 : years.value.length
|
|
5197
|
+
);
|
|
5198
|
+
const overlayContext = injectCalendarMonthYearOverlayContext();
|
|
5199
|
+
const dataValue = vue.computed(() => `${props.type}-${props.date[props.type]}`);
|
|
5200
|
+
const isFocusedDate = vue.computed(() => {
|
|
5201
|
+
if (props.type === "month")
|
|
5202
|
+
return rootContext.currentMonth.value === props.date.monthName;
|
|
5203
|
+
return rootContext.currentYear.value === props.date.year.toString();
|
|
5204
|
+
});
|
|
5205
|
+
function closeOverlay() {
|
|
5206
|
+
rootContext.monthYearOverlayState.value = false;
|
|
5207
|
+
}
|
|
5174
5208
|
function handleClick() {
|
|
5175
5209
|
if (rootContext.isDateDisabled(props.date) || rootContext.isDateUnavailable?.(props.date))
|
|
5176
5210
|
return;
|
|
5177
5211
|
rootContext.onDateChange(props.date);
|
|
5178
|
-
|
|
5212
|
+
closeOverlay();
|
|
5213
|
+
}
|
|
5214
|
+
const kbd = useKbd();
|
|
5215
|
+
function handleArrowKey(e) {
|
|
5216
|
+
if (props.disabled) return;
|
|
5217
|
+
e.preventDefault();
|
|
5218
|
+
e.stopPropagation();
|
|
5219
|
+
const parentElement = rootContext.parentElement.value;
|
|
5220
|
+
const indexIncrementation = overlayContext.itemsPerRow.value;
|
|
5221
|
+
const sign = rootContext.dir.value === "rtl" ? -1 : 1;
|
|
5222
|
+
switch (e.code) {
|
|
5223
|
+
case kbd.ARROW_RIGHT:
|
|
5224
|
+
shiftFocus(props.date, sign);
|
|
5225
|
+
break;
|
|
5226
|
+
case kbd.ARROW_LEFT:
|
|
5227
|
+
shiftFocus(props.date, -sign);
|
|
5228
|
+
break;
|
|
5229
|
+
case kbd.ARROW_UP:
|
|
5230
|
+
shiftFocus(props.date, -indexIncrementation);
|
|
5231
|
+
break;
|
|
5232
|
+
case kbd.ARROW_DOWN:
|
|
5233
|
+
shiftFocus(props.date, indexIncrementation);
|
|
5234
|
+
break;
|
|
5235
|
+
case kbd.ENTER:
|
|
5236
|
+
case kbd.SPACE_CODE:
|
|
5237
|
+
rootContext.onDateChange(props.date);
|
|
5238
|
+
closeOverlay();
|
|
5239
|
+
}
|
|
5240
|
+
function shiftFocus(date2, add) {
|
|
5241
|
+
let nextDate = date2[props.type] + add;
|
|
5242
|
+
if (nextDate <= 0) {
|
|
5243
|
+
nextDate = maxValue.value + nextDate;
|
|
5244
|
+
}
|
|
5245
|
+
if (nextDate > years.value[maxValue.value - 1].year) {
|
|
5246
|
+
nextDate = nextDate - maxValue.value;
|
|
5247
|
+
}
|
|
5248
|
+
const candidateDay = parentElement.querySelector(
|
|
5249
|
+
`[data-value='${props.type}-${nextDate}']`
|
|
5250
|
+
);
|
|
5251
|
+
candidateDay?.focus();
|
|
5252
|
+
}
|
|
5179
5253
|
}
|
|
5180
5254
|
return (_ctx, _cache) => {
|
|
5181
|
-
return vue.openBlock(), vue.createBlock(vue.unref(Primitive), vue.mergeProps(props, {
|
|
5255
|
+
return vue.openBlock(), vue.createBlock(vue.unref(Primitive), vue.mergeProps(props, {
|
|
5256
|
+
onClick: handleClick,
|
|
5257
|
+
ref: "primitiveElement",
|
|
5258
|
+
role: "button",
|
|
5259
|
+
"aria-disabled": __props.disabled,
|
|
5260
|
+
"data-value": dataValue.value,
|
|
5261
|
+
onKeydown: [
|
|
5262
|
+
vue.withKeys(handleArrowKey, ["up", "down", "left", "right", "space", "enter"]),
|
|
5263
|
+
_cache[0] || (_cache[0] = vue.withKeys(vue.withModifiers(() => {
|
|
5264
|
+
}, ["prevent"]), ["enter"]))
|
|
5265
|
+
],
|
|
5266
|
+
tabindex: isFocusedDate.value ? 0 : -1
|
|
5267
|
+
}), {
|
|
5182
5268
|
default: vue.withCtx(() => [
|
|
5183
5269
|
vue.renderSlot(_ctx.$slots, "default")
|
|
5184
5270
|
]),
|
|
5185
5271
|
_: 3
|
|
5186
|
-
}, 16);
|
|
5272
|
+
}, 16, ["aria-disabled", "data-value", "tabindex"]);
|
|
5187
5273
|
};
|
|
5188
5274
|
}
|
|
5189
5275
|
});
|
|
@@ -5191,6 +5277,8 @@ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
|
|
|
5191
5277
|
__name: "DatePickerOverlayItem",
|
|
5192
5278
|
props: {
|
|
5193
5279
|
date: {},
|
|
5280
|
+
disabled: { type: Boolean },
|
|
5281
|
+
type: {},
|
|
5194
5282
|
asChild: { type: Boolean },
|
|
5195
5283
|
as: {}
|
|
5196
5284
|
},
|