@agile-plus/headless 0.1.2 → 0.2.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/README.md +24 -17
- package/dist/index.cjs +4163 -223
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +4258 -216
- package/dist/index.js.map +1 -1
- package/dist/types-BxsQI7P5.d.cts +93 -0
- package/dist/types-BxsQI7P5.d.ts +93 -0
- package/dist/types-zpeY0yvD.d.cts +73 -0
- package/dist/types-zpeY0yvD.d.ts +73 -0
- package/dist/useAccordion/index.cjs +149 -0
- package/dist/useAccordion/index.cjs.map +1 -0
- package/dist/useAccordion/index.d.cts +119 -0
- package/dist/useAccordion/index.d.ts +119 -0
- package/dist/useAccordion/index.js +128 -0
- package/dist/useAccordion/index.js.map +1 -0
- package/dist/useAvatar/index.cjs +135 -0
- package/dist/useAvatar/index.cjs.map +1 -0
- package/dist/useAvatar/index.d.cts +120 -0
- package/dist/useAvatar/index.d.ts +120 -0
- package/dist/useAvatar/index.js +106 -0
- package/dist/useAvatar/index.js.map +1 -0
- package/dist/useCheckbox/index.cjs +3 -1
- package/dist/useCheckbox/index.cjs.map +1 -1
- package/dist/useCheckbox/index.js +3 -1
- package/dist/useCheckbox/index.js.map +1 -1
- package/dist/useCollapsible/index.cjs +10 -0
- package/dist/useCollapsible/index.cjs.map +1 -1
- package/dist/useCollapsible/index.js +11 -1
- package/dist/useCollapsible/index.js.map +1 -1
- package/dist/useDatePicker/index.cjs +684 -0
- package/dist/useDatePicker/index.cjs.map +1 -0
- package/dist/useDatePicker/index.d.cts +191 -0
- package/dist/useDatePicker/index.d.ts +191 -0
- package/dist/useDatePicker/index.js +671 -0
- package/dist/useDatePicker/index.js.map +1 -0
- package/dist/useDateRangePicker/index.cjs +614 -0
- package/dist/useDateRangePicker/index.cjs.map +1 -0
- package/dist/useDateRangePicker/index.d.cts +159 -0
- package/dist/useDateRangePicker/index.d.ts +159 -0
- package/dist/useDateRangePicker/index.js +601 -0
- package/dist/useDateRangePicker/index.js.map +1 -0
- package/dist/useDialog/index.cjs.map +1 -1
- package/dist/useDialog/index.js.map +1 -1
- package/dist/useDropdownMenu/index.cjs +468 -0
- package/dist/useDropdownMenu/index.cjs.map +1 -0
- package/dist/useDropdownMenu/index.d.cts +73 -0
- package/dist/useDropdownMenu/index.d.ts +73 -0
- package/dist/useDropdownMenu/index.js +441 -0
- package/dist/useDropdownMenu/index.js.map +1 -0
- package/dist/useEllipsis/index.cjs +181 -0
- package/dist/useEllipsis/index.cjs.map +1 -0
- package/dist/useEllipsis/index.d.cts +67 -0
- package/dist/useEllipsis/index.d.ts +67 -0
- package/dist/useEllipsis/index.js +162 -0
- package/dist/useEllipsis/index.js.map +1 -0
- package/dist/useFloating/index.cjs +177 -0
- package/dist/useFloating/index.cjs.map +1 -0
- package/dist/useFloating/index.d.cts +21 -0
- package/dist/useFloating/index.d.ts +21 -0
- package/dist/useFloating/index.js +150 -0
- package/dist/useFloating/index.js.map +1 -0
- package/dist/useFormControl/index.cjs +5 -0
- package/dist/useFormControl/index.cjs.map +1 -1
- package/dist/useFormControl/index.js +5 -0
- package/dist/useFormControl/index.js.map +1 -1
- package/dist/useInput/index.cjs +192 -0
- package/dist/useInput/index.cjs.map +1 -0
- package/dist/useInput/index.d.cts +41 -0
- package/dist/useInput/index.d.ts +41 -0
- package/dist/useInput/index.js +165 -0
- package/dist/useInput/index.js.map +1 -0
- package/dist/useKeepMounted/index.cjs +44 -0
- package/dist/useKeepMounted/index.cjs.map +1 -0
- package/dist/useKeepMounted/index.d.cts +45 -0
- package/dist/useKeepMounted/index.d.ts +45 -0
- package/dist/useKeepMounted/index.js +17 -0
- package/dist/useKeepMounted/index.js.map +1 -0
- package/dist/useMenu/index.cjs +438 -0
- package/dist/useMenu/index.cjs.map +1 -0
- package/dist/useMenu/index.d.cts +134 -0
- package/dist/useMenu/index.d.ts +134 -0
- package/dist/useMenu/index.js +419 -0
- package/dist/useMenu/index.js.map +1 -0
- package/dist/usePagination/index.cjs +113 -0
- package/dist/usePagination/index.cjs.map +1 -0
- package/dist/usePagination/index.d.cts +139 -0
- package/dist/usePagination/index.d.ts +139 -0
- package/dist/usePagination/index.js +95 -0
- package/dist/usePagination/index.js.map +1 -0
- package/dist/usePopover/index.cjs +312 -0
- package/dist/usePopover/index.cjs.map +1 -0
- package/dist/usePopover/index.d.cts +71 -0
- package/dist/usePopover/index.d.ts +71 -0
- package/dist/usePopover/index.js +285 -0
- package/dist/usePopover/index.js.map +1 -0
- package/dist/useSelect/index.cjs +729 -0
- package/dist/useSelect/index.cjs.map +1 -0
- package/dist/useSelect/index.d.cts +193 -0
- package/dist/useSelect/index.d.ts +193 -0
- package/dist/useSelect/index.js +710 -0
- package/dist/useSelect/index.js.map +1 -0
- package/dist/useSplitter/index.cjs +558 -0
- package/dist/useSplitter/index.cjs.map +1 -0
- package/dist/useSplitter/index.d.cts +307 -0
- package/dist/useSplitter/index.d.ts +307 -0
- package/dist/useSplitter/index.js +541 -0
- package/dist/useSplitter/index.js.map +1 -0
- package/dist/useSwitch/index.cjs +4 -1
- package/dist/useSwitch/index.cjs.map +1 -1
- package/dist/useSwitch/index.js +4 -1
- package/dist/useSwitch/index.js.map +1 -1
- package/dist/useTable/index.cjs +308 -0
- package/dist/useTable/index.cjs.map +1 -0
- package/dist/useTable/index.d.cts +242 -0
- package/dist/useTable/index.d.ts +242 -0
- package/dist/useTable/index.js +301 -0
- package/dist/useTable/index.js.map +1 -0
- package/dist/useTabs/index.cjs +13 -4
- package/dist/useTabs/index.cjs.map +1 -1
- package/dist/useTabs/index.d.cts +5 -1
- package/dist/useTabs/index.d.ts +5 -1
- package/dist/useTabs/index.js +13 -4
- package/dist/useTabs/index.js.map +1 -1
- package/dist/useTextControl-Dcq0GFmg.d.cts +63 -0
- package/dist/useTextControl-Dcq0GFmg.d.ts +63 -0
- package/dist/useTextarea/index.cjs +186 -0
- package/dist/useTextarea/index.cjs.map +1 -0
- package/dist/useTextarea/index.d.cts +30 -0
- package/dist/useTextarea/index.d.ts +30 -0
- package/dist/useTextarea/index.js +159 -0
- package/dist/useTextarea/index.js.map +1 -0
- package/dist/useToast/index.cjs +27 -20
- package/dist/useToast/index.cjs.map +1 -1
- package/dist/useToast/index.js +27 -20
- package/dist/useToast/index.js.map +1 -1
- package/dist/useToastViewport/index.cjs +1 -3
- package/dist/useToastViewport/index.cjs.map +1 -1
- package/dist/useToastViewport/index.js +1 -3
- package/dist/useToastViewport/index.js.map +1 -1
- package/dist/useTooltip/index.cjs +357 -0
- package/dist/useTooltip/index.cjs.map +1 -0
- package/dist/useTooltip/index.d.cts +81 -0
- package/dist/useTooltip/index.d.ts +81 -0
- package/dist/useTooltip/index.js +338 -0
- package/dist/useTooltip/index.js.map +1 -0
- package/dist/useVirtualList/index.cjs +308 -0
- package/dist/useVirtualList/index.cjs.map +1 -0
- package/dist/useVirtualList/index.d.cts +31 -0
- package/dist/useVirtualList/index.d.ts +31 -0
- package/dist/useVirtualList/index.js +288 -0
- package/dist/useVirtualList/index.js.map +1 -0
- package/dist/useVirtualTree/index.cjs +520 -0
- package/dist/useVirtualTree/index.cjs.map +1 -0
- package/dist/useVirtualTree/index.d.cts +146 -0
- package/dist/useVirtualTree/index.d.ts +146 -0
- package/dist/useVirtualTree/index.js +511 -0
- package/dist/useVirtualTree/index.js.map +1 -0
- package/package.json +121 -2
- package/src/index.ts +38 -0
- package/src/useAccordion/index.ts +7 -0
- package/src/useAccordion/types.ts +118 -0
- package/src/useAccordion/useAccordion.ts +130 -0
- package/src/useAvatar/index.ts +14 -0
- package/src/useAvatar/types.ts +90 -0
- package/src/useAvatar/useAvatar.ts +39 -0
- package/src/useAvatar/useAvatarFallback.ts +62 -0
- package/src/useAvatar/useAvatarImage.ts +78 -0
- package/src/useCheckbox/useCheckbox.ts +4 -1
- package/src/useCollapsible/useCollapsible.ts +22 -1
- package/src/useDatePicker/index.ts +9 -0
- package/src/useDatePicker/types.ts +177 -0
- package/src/useDatePicker/useDatePicker.ts +688 -0
- package/src/useDateRangePicker/index.ts +8 -0
- package/src/useDateRangePicker/types.ts +146 -0
- package/src/useDateRangePicker/useDateRangePicker.ts +618 -0
- package/src/useDropdownMenu/index.ts +3 -0
- package/src/useDropdownMenu/types.ts +61 -0
- package/src/useDropdownMenu/useDropdownMenu.ts +322 -0
- package/src/useEllipsis/index.ts +3 -0
- package/src/useEllipsis/types.ts +51 -0
- package/src/useEllipsis/useEllipsis.ts +169 -0
- package/src/useFloating/index.ts +3 -0
- package/src/useFloating/types.ts +79 -0
- package/src/useFloating/useFloating.ts +199 -0
- package/src/useFormControl/useFormControl.ts +13 -0
- package/src/useInput/index.ts +3 -0
- package/src/useInput/types.ts +29 -0
- package/src/useInput/useInput.ts +40 -0
- package/src/useKeepMounted/index.ts +3 -0
- package/src/useKeepMounted/types.ts +29 -0
- package/src/useKeepMounted/useKeepMounted.ts +34 -0
- package/src/useMenu/index.ts +9 -0
- package/src/useMenu/types.ts +126 -0
- package/src/useMenu/useMenu.ts +504 -0
- package/src/usePagination/index.ts +3 -0
- package/src/usePagination/types.ts +137 -0
- package/src/usePagination/usePagination.ts +109 -0
- package/src/usePopover/index.ts +3 -0
- package/src/usePopover/types.ts +65 -0
- package/src/usePopover/usePopover.ts +157 -0
- package/src/useSelect/index.ts +9 -0
- package/src/useSelect/types.ts +184 -0
- package/src/useSelect/useSelect.ts +713 -0
- package/src/useSplitter/index.ts +10 -0
- package/src/useSplitter/types.ts +336 -0
- package/src/useSplitter/useSplitter.ts +648 -0
- package/src/useSplitter/useSplitterPanel.ts +106 -0
- package/src/useSwitch/useSwitch.ts +6 -1
- package/src/useTable/index.ts +3 -0
- package/src/useTable/types.ts +282 -0
- package/src/useTable/useTable.ts +407 -0
- package/src/useTabs/types.ts +5 -1
- package/src/useTabs/useTabs.ts +30 -6
- package/src/useTextarea/index.ts +3 -0
- package/src/useTextarea/types.ts +17 -0
- package/src/useTextarea/useTextarea.ts +34 -0
- package/src/useToast/useToast.ts +43 -26
- package/src/useToastViewport/useToastViewport.ts +10 -9
- package/src/useTooltip/index.ts +3 -0
- package/src/useTooltip/types.ts +72 -0
- package/src/useTooltip/useTooltip.ts +240 -0
- package/src/useVirtualList/index.ts +8 -0
- package/src/useVirtualList/types.ts +95 -0
- package/src/useVirtualList/useVirtualList.ts +478 -0
- package/src/useVirtualTree/index.ts +3 -0
- package/src/useVirtualTree/types.ts +179 -0
- package/src/useVirtualTree/useVirtualTree.ts +342 -0
- package/src/utils/useFocusTrap.ts +2 -0
- package/src/utils/useTextControl.ts +191 -0
|
@@ -0,0 +1,684 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/useDatePicker/index.ts
|
|
21
|
+
var useDatePicker_exports = {};
|
|
22
|
+
__export(useDatePicker_exports, {
|
|
23
|
+
useDatePicker: () => useDatePicker
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(useDatePicker_exports);
|
|
26
|
+
|
|
27
|
+
// src/useDatePicker/useDatePicker.ts
|
|
28
|
+
var import_vue5 = require("vue");
|
|
29
|
+
var import_date = require("@agile-plus/primitives/date");
|
|
30
|
+
|
|
31
|
+
// src/utils/useControllable.ts
|
|
32
|
+
var import_vue = require("vue");
|
|
33
|
+
function useControllable(options) {
|
|
34
|
+
const controlled = (0, import_vue.computed)(() => (0, import_vue.toValue)(options.value));
|
|
35
|
+
const isControlled = (0, import_vue.computed)(() => controlled.value !== void 0);
|
|
36
|
+
const internal = (0, import_vue.shallowRef)(options.defaultValue);
|
|
37
|
+
const value = (0, import_vue.computed)(() => {
|
|
38
|
+
const current = controlled.value;
|
|
39
|
+
return current === void 0 ? internal.value : current;
|
|
40
|
+
});
|
|
41
|
+
function set(next) {
|
|
42
|
+
if (!isControlled.value) internal.value = next;
|
|
43
|
+
options.onChange?.(next);
|
|
44
|
+
}
|
|
45
|
+
function replace(next) {
|
|
46
|
+
if (isControlled.value) return;
|
|
47
|
+
internal.value = next;
|
|
48
|
+
}
|
|
49
|
+
return { value, isControlled, set, replace };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/utils/useFormResetListener.ts
|
|
53
|
+
var import_vue2 = require("vue");
|
|
54
|
+
|
|
55
|
+
// src/utils/env.ts
|
|
56
|
+
var isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
57
|
+
function isObserverAvailable(constructor) {
|
|
58
|
+
return typeof constructor === "function";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/utils/useFormResetListener.ts
|
|
62
|
+
function resolveForm(element, formId) {
|
|
63
|
+
if (!isBrowser) return null;
|
|
64
|
+
if (formId) {
|
|
65
|
+
const node = document.getElementById(formId);
|
|
66
|
+
return node instanceof HTMLFormElement ? node : null;
|
|
67
|
+
}
|
|
68
|
+
const native = element && "form" in element ? element.form : null;
|
|
69
|
+
if (native instanceof HTMLFormElement) return native;
|
|
70
|
+
const closest = element?.closest("form");
|
|
71
|
+
return closest instanceof HTMLFormElement ? closest : null;
|
|
72
|
+
}
|
|
73
|
+
function useFormResetListener(control, onReset, formId) {
|
|
74
|
+
let target = null;
|
|
75
|
+
function detach() {
|
|
76
|
+
if (!target) return;
|
|
77
|
+
target.removeEventListener("reset", onReset);
|
|
78
|
+
target = null;
|
|
79
|
+
}
|
|
80
|
+
(0, import_vue2.watch)(
|
|
81
|
+
[control, () => (0, import_vue2.toValue)(formId)],
|
|
82
|
+
([element, nextFormId]) => {
|
|
83
|
+
detach();
|
|
84
|
+
if (!isBrowser) return;
|
|
85
|
+
const form = resolveForm(element, nextFormId);
|
|
86
|
+
if (!form) return;
|
|
87
|
+
form.addEventListener("reset", onReset);
|
|
88
|
+
target = form;
|
|
89
|
+
},
|
|
90
|
+
{ flush: "post" }
|
|
91
|
+
);
|
|
92
|
+
(0, import_vue2.onScopeDispose)(detach);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/useFloating/useFloating.ts
|
|
96
|
+
var import_vue4 = require("vue");
|
|
97
|
+
var import_floating = require("@agile-plus/primitives/floating");
|
|
98
|
+
|
|
99
|
+
// src/utils/useResizeObserver.ts
|
|
100
|
+
var import_vue3 = require("vue");
|
|
101
|
+
function useResizeObserver(onResize) {
|
|
102
|
+
let observer = null;
|
|
103
|
+
function observe(element) {
|
|
104
|
+
if (!element || !isBrowser || !isObserverAvailable(globalThis.ResizeObserver)) return;
|
|
105
|
+
observer ??= new ResizeObserver(() => onResize());
|
|
106
|
+
observer.observe(element);
|
|
107
|
+
}
|
|
108
|
+
function unobserve(element) {
|
|
109
|
+
observer?.unobserve(element);
|
|
110
|
+
}
|
|
111
|
+
function disconnect() {
|
|
112
|
+
observer?.disconnect();
|
|
113
|
+
observer = null;
|
|
114
|
+
}
|
|
115
|
+
(0, import_vue3.onScopeDispose)(disconnect);
|
|
116
|
+
return { observe, unobserve, disconnect };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/useFloating/useFloating.ts
|
|
120
|
+
function useFloating(options = {}) {
|
|
121
|
+
const referenceRef = (0, import_vue4.ref)(null);
|
|
122
|
+
const floatingRef = (0, import_vue4.ref)(null);
|
|
123
|
+
const x = (0, import_vue4.ref)(0);
|
|
124
|
+
const y = (0, import_vue4.ref)(0);
|
|
125
|
+
const placement = (0, import_vue4.ref)((0, import_vue4.toValue)(options.placement) ?? "bottom");
|
|
126
|
+
const arrow = (0, import_vue4.ref)(null);
|
|
127
|
+
const availableSpace = (0, import_vue4.ref)(null);
|
|
128
|
+
const isOpen = (0, import_vue4.computed)(() => (0, import_vue4.toValue)(options.open) ?? true);
|
|
129
|
+
const strategy = (0, import_vue4.computed)(() => options.strategy ?? "absolute");
|
|
130
|
+
let frame = null;
|
|
131
|
+
const resize = useResizeObserver(requestUpdate);
|
|
132
|
+
function requestUpdate() {
|
|
133
|
+
if (!isBrowser || frame !== null) return;
|
|
134
|
+
frame = window.requestAnimationFrame(() => {
|
|
135
|
+
frame = null;
|
|
136
|
+
measure();
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function measure() {
|
|
140
|
+
const reference = referenceRef.value;
|
|
141
|
+
const floating = floatingRef.value;
|
|
142
|
+
if (!reference || !floating) return;
|
|
143
|
+
const referenceRect = reference.getBoundingClientRect();
|
|
144
|
+
const floatingRect = floating.getBoundingClientRect();
|
|
145
|
+
const boundaryRect = (0, import_vue4.toValue)(options.boundary)?.getBoundingClientRect();
|
|
146
|
+
const viewport = { width: window.innerWidth, height: window.innerHeight };
|
|
147
|
+
const scrollX = window.scrollX;
|
|
148
|
+
const scrollY = window.scrollY;
|
|
149
|
+
const snapshot = {
|
|
150
|
+
reference: {
|
|
151
|
+
x: referenceRect.x,
|
|
152
|
+
y: referenceRect.y,
|
|
153
|
+
width: referenceRect.width,
|
|
154
|
+
height: referenceRect.height
|
|
155
|
+
},
|
|
156
|
+
// 浮层自己的 x/y 是上一轮结果,传 0 以免本轮输出依赖历史状态。
|
|
157
|
+
floating: { x: 0, y: 0, width: floatingRect.width, height: floatingRect.height },
|
|
158
|
+
viewport,
|
|
159
|
+
...boundaryRect ? {
|
|
160
|
+
boundary: {
|
|
161
|
+
x: boundaryRect.x,
|
|
162
|
+
y: boundaryRect.y,
|
|
163
|
+
width: boundaryRect.width,
|
|
164
|
+
height: boundaryRect.height
|
|
165
|
+
}
|
|
166
|
+
} : {}
|
|
167
|
+
};
|
|
168
|
+
const floatingOptions = {
|
|
169
|
+
placement: (0, import_vue4.toValue)(options.placement),
|
|
170
|
+
offset: options.offset,
|
|
171
|
+
flip: options.flip,
|
|
172
|
+
shift: options.shift,
|
|
173
|
+
padding: options.padding,
|
|
174
|
+
arrow: options.arrow
|
|
175
|
+
};
|
|
176
|
+
const result = (0, import_floating.computeFloatingPosition)(snapshot, floatingOptions);
|
|
177
|
+
x.value = strategy.value === "absolute" ? result.x + scrollX : result.x;
|
|
178
|
+
y.value = strategy.value === "absolute" ? result.y + scrollY : result.y;
|
|
179
|
+
placement.value = result.placement;
|
|
180
|
+
arrow.value = result.arrow;
|
|
181
|
+
availableSpace.value = (0, import_floating.computeAvailableSpace)(snapshot, result.placement, floatingOptions);
|
|
182
|
+
}
|
|
183
|
+
const floatingStyle = (0, import_vue4.computed)(() => ({
|
|
184
|
+
position: strategy.value,
|
|
185
|
+
left: 0,
|
|
186
|
+
top: 0,
|
|
187
|
+
transform: `translate(${x.value}px, ${y.value}px)`
|
|
188
|
+
}));
|
|
189
|
+
const arrowStyle = (0, import_vue4.computed)(() => {
|
|
190
|
+
const offset = arrow.value;
|
|
191
|
+
if (!offset) return {};
|
|
192
|
+
return offset.x !== null ? { position: "absolute", left: `${offset.x}px` } : { position: "absolute", top: `${offset.y}px` };
|
|
193
|
+
});
|
|
194
|
+
function attach() {
|
|
195
|
+
window.addEventListener("scroll", requestUpdate, true);
|
|
196
|
+
window.addEventListener("resize", requestUpdate);
|
|
197
|
+
resize.observe(referenceRef.value);
|
|
198
|
+
resize.observe(floatingRef.value);
|
|
199
|
+
}
|
|
200
|
+
function detach() {
|
|
201
|
+
if (!isBrowser) return;
|
|
202
|
+
window.removeEventListener("scroll", requestUpdate, true);
|
|
203
|
+
window.removeEventListener("resize", requestUpdate);
|
|
204
|
+
resize.disconnect();
|
|
205
|
+
}
|
|
206
|
+
(0, import_vue4.watch)(
|
|
207
|
+
[isOpen, referenceRef, floatingRef],
|
|
208
|
+
([open]) => {
|
|
209
|
+
detach();
|
|
210
|
+
if (!isBrowser || !open) return;
|
|
211
|
+
attach();
|
|
212
|
+
void (0, import_vue4.nextTick)(measure);
|
|
213
|
+
},
|
|
214
|
+
{ immediate: true }
|
|
215
|
+
);
|
|
216
|
+
(0, import_vue4.onScopeDispose)(() => {
|
|
217
|
+
detach();
|
|
218
|
+
if (frame !== null && isBrowser) {
|
|
219
|
+
window.cancelAnimationFrame(frame);
|
|
220
|
+
frame = null;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
return {
|
|
224
|
+
referenceRef,
|
|
225
|
+
floatingRef,
|
|
226
|
+
x: (0, import_vue4.computed)(() => x.value),
|
|
227
|
+
y: (0, import_vue4.computed)(() => y.value),
|
|
228
|
+
placement: (0, import_vue4.computed)(() => placement.value),
|
|
229
|
+
availableSpace: (0, import_vue4.computed)(() => availableSpace.value),
|
|
230
|
+
floatingStyle,
|
|
231
|
+
arrowStyle,
|
|
232
|
+
update: requestUpdate
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// src/useDatePicker/useDatePicker.ts
|
|
237
|
+
var DEFAULT_OFFSET = 4;
|
|
238
|
+
var DEFAULT_PADDING = 8;
|
|
239
|
+
var DEFAULT_VALUE_FORMAT = "YYYY-MM-DD";
|
|
240
|
+
var DEFAULT_DATETIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
|
|
241
|
+
var HOURS_PER_DAY = 24;
|
|
242
|
+
var MINUTES_PER_HOUR = 60;
|
|
243
|
+
var SECONDS_PER_MINUTE = 60;
|
|
244
|
+
var DEFAULT_FIRST_DAY_OF_WEEK = 1;
|
|
245
|
+
var DAYS_PER_WEEK = 7;
|
|
246
|
+
function useDatePicker(options = {}) {
|
|
247
|
+
const uid = (0, import_vue5.useId)();
|
|
248
|
+
const triggerId = `date-picker-trigger-${uid}`;
|
|
249
|
+
const contentId = `date-picker-content-${uid}`;
|
|
250
|
+
const showTime = (0, import_vue5.computed)(() => (0, import_vue5.toValue)(options.showTime) === true);
|
|
251
|
+
const valueFormat = (0, import_vue5.computed)(
|
|
252
|
+
() => (0, import_vue5.toValue)(options.valueFormat) ?? (showTime.value ? DEFAULT_DATETIME_FORMAT : DEFAULT_VALUE_FORMAT)
|
|
253
|
+
);
|
|
254
|
+
const format = (0, import_vue5.computed)(
|
|
255
|
+
() => (0, import_vue5.toValue)(options.format) ?? (showTime.value ? DEFAULT_DATETIME_FORMAT : DEFAULT_VALUE_FORMAT)
|
|
256
|
+
);
|
|
257
|
+
const valueState = useControllable({
|
|
258
|
+
value: () => (0, import_vue5.toValue)(options.modelValue),
|
|
259
|
+
defaultValue: options.defaultValue ?? null,
|
|
260
|
+
onChange: (next) => options.onValueChange?.(next)
|
|
261
|
+
});
|
|
262
|
+
const openState = useControllable({
|
|
263
|
+
value: () => (0, import_vue5.toValue)(options.open),
|
|
264
|
+
defaultValue: options.defaultOpen ?? false,
|
|
265
|
+
onChange: (next) => options.onOpenChange?.(next)
|
|
266
|
+
});
|
|
267
|
+
const value = valueState.value;
|
|
268
|
+
const isOpen = openState.value;
|
|
269
|
+
const isDisabled = (0, import_vue5.computed)(() => (0, import_vue5.toValue)(options.disabled) === true);
|
|
270
|
+
const firstDayOfWeek = (0, import_vue5.computed)(() => {
|
|
271
|
+
const raw = (0, import_vue5.toValue)(options.firstDayOfWeek) ?? DEFAULT_FIRST_DAY_OF_WEEK;
|
|
272
|
+
return (raw % DAYS_PER_WEEK + DAYS_PER_WEEK) % DAYS_PER_WEEK;
|
|
273
|
+
});
|
|
274
|
+
const selectedDate = (0, import_vue5.computed)(() => {
|
|
275
|
+
const current = value.value;
|
|
276
|
+
if (current === null || current === "") return null;
|
|
277
|
+
return (0, import_date.parseDate)(current, valueFormat.value);
|
|
278
|
+
});
|
|
279
|
+
const panel = (0, import_vue5.ref)("date");
|
|
280
|
+
const panelDate = (0, import_vue5.ref)(startOfMonth(selectedDate.value ?? /* @__PURE__ */ new Date()));
|
|
281
|
+
const focusedDate = (0, import_vue5.ref)((0, import_date.startOfDay)(selectedDate.value ?? /* @__PURE__ */ new Date()));
|
|
282
|
+
const draft = (0, import_vue5.ref)(null);
|
|
283
|
+
let skipFocusOpen = false;
|
|
284
|
+
const floating = useFloating({
|
|
285
|
+
placement: options.placement ?? "bottom-start",
|
|
286
|
+
offset: options.offset ?? DEFAULT_OFFSET,
|
|
287
|
+
flip: options.flip,
|
|
288
|
+
shift: options.shift,
|
|
289
|
+
padding: options.padding ?? DEFAULT_PADDING,
|
|
290
|
+
strategy: options.strategy,
|
|
291
|
+
open: isOpen
|
|
292
|
+
});
|
|
293
|
+
const displayText = (0, import_vue5.computed)(() => {
|
|
294
|
+
if (draft.value !== null) return draft.value;
|
|
295
|
+
return selectedDate.value ? (0, import_date.formatDate)(selectedDate.value, format.value) : "";
|
|
296
|
+
});
|
|
297
|
+
const dateCells = (0, import_vue5.computed)(
|
|
298
|
+
() => (0, import_date.getCalendarGrid)({
|
|
299
|
+
year: panelDate.value.getFullYear(),
|
|
300
|
+
month: panelDate.value.getMonth(),
|
|
301
|
+
firstDayOfWeek: firstDayOfWeek.value
|
|
302
|
+
})
|
|
303
|
+
);
|
|
304
|
+
const monthCells = (0, import_vue5.computed)(() => (0, import_date.getMonthGrid)(panelDate.value.getFullYear()));
|
|
305
|
+
const yearCells = (0, import_vue5.computed)(() => (0, import_date.getYearGrid)(panelDate.value.getFullYear()));
|
|
306
|
+
const weekdayLabels = (0, import_vue5.computed)(() => (0, import_date.getWeekdayLabels)(firstDayOfWeek.value));
|
|
307
|
+
const headerLabel = (0, import_vue5.computed)(() => (0, import_date.formatDate)(panelDate.value, "YYYY\u5E74 M\u6708"));
|
|
308
|
+
const decadeLabel = (0, import_vue5.computed)(() => (0, import_date.getDecadeLabel)(panelDate.value.getFullYear()));
|
|
309
|
+
function isDateDisabled(date) {
|
|
310
|
+
if (isDisabled.value) return true;
|
|
311
|
+
return options.disabledDate ? options.disabledDate((0, import_date.startOfDay)(date)) : false;
|
|
312
|
+
}
|
|
313
|
+
const isTodayDisabled = (0, import_vue5.computed)(() => isDateDisabled(/* @__PURE__ */ new Date()));
|
|
314
|
+
function getCellState(date) {
|
|
315
|
+
const selected = selectedDate.value;
|
|
316
|
+
return {
|
|
317
|
+
selected: selected !== null && (0, import_date.isSameDay)(selected, date),
|
|
318
|
+
disabled: isDateDisabled(date),
|
|
319
|
+
today: (0, import_date.isSameDay)(/* @__PURE__ */ new Date(), date),
|
|
320
|
+
inMonth: (0, import_date.isSameMonth)(panelDate.value, date)
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
function startOfMonth(date) {
|
|
324
|
+
return new Date(date.getFullYear(), date.getMonth(), 1);
|
|
325
|
+
}
|
|
326
|
+
function syncView(date) {
|
|
327
|
+
focusedDate.value = (0, import_date.startOfDay)(date);
|
|
328
|
+
panelDate.value = startOfMonth(date);
|
|
329
|
+
}
|
|
330
|
+
function getCellId(date, kind) {
|
|
331
|
+
const normalized = kind === "month" ? startOfMonth(date) : kind === "year" ? new Date(date.getFullYear(), 0, 1) : date;
|
|
332
|
+
return `date-picker-cell-${uid}-${kind}-${(0, import_date.formatDate)(normalized, DEFAULT_VALUE_FORMAT)}`;
|
|
333
|
+
}
|
|
334
|
+
function open() {
|
|
335
|
+
if (isDisabled.value) return;
|
|
336
|
+
panel.value = "date";
|
|
337
|
+
syncView(selectedDate.value ?? /* @__PURE__ */ new Date());
|
|
338
|
+
openState.set(true);
|
|
339
|
+
}
|
|
340
|
+
function close() {
|
|
341
|
+
const content = floating.floatingRef.value;
|
|
342
|
+
const active = isBrowser ? document.activeElement : null;
|
|
343
|
+
draft.value = null;
|
|
344
|
+
panel.value = "date";
|
|
345
|
+
openState.set(false);
|
|
346
|
+
if (content && active instanceof Node && content.contains(active)) {
|
|
347
|
+
skipFocusOpen = true;
|
|
348
|
+
floating.referenceRef.value?.focus();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
function selectDate(date) {
|
|
352
|
+
if (isDateDisabled(date)) return;
|
|
353
|
+
const next = showTime.value ? withSelectedTime(date) : (0, import_date.startOfDay)(date);
|
|
354
|
+
valueState.set((0, import_date.formatDate)(next, valueFormat.value));
|
|
355
|
+
if (!showTime.value) close();
|
|
356
|
+
}
|
|
357
|
+
function withSelectedTime(date) {
|
|
358
|
+
const next = (0, import_date.startOfDay)(date);
|
|
359
|
+
const current = selectedDate.value;
|
|
360
|
+
if (current) {
|
|
361
|
+
next.setHours(current.getHours(), current.getMinutes(), current.getSeconds());
|
|
362
|
+
}
|
|
363
|
+
return next;
|
|
364
|
+
}
|
|
365
|
+
const timeParts = (0, import_vue5.computed)(() => {
|
|
366
|
+
const current = selectedDate.value;
|
|
367
|
+
return {
|
|
368
|
+
hour: current?.getHours() ?? 0,
|
|
369
|
+
minute: current?.getMinutes() ?? 0,
|
|
370
|
+
second: current?.getSeconds() ?? 0
|
|
371
|
+
};
|
|
372
|
+
});
|
|
373
|
+
function setTimePart(part, amount) {
|
|
374
|
+
if (isDisabled.value) return;
|
|
375
|
+
const limit = part === "hour" ? HOURS_PER_DAY : part === "minute" ? MINUTES_PER_HOUR : SECONDS_PER_MINUTE;
|
|
376
|
+
if (!Number.isInteger(amount) || amount < 0 || amount >= limit) return;
|
|
377
|
+
const next = new Date(selectedDate.value ?? (0, import_date.startOfDay)(/* @__PURE__ */ new Date()));
|
|
378
|
+
if (part === "hour") next.setHours(amount);
|
|
379
|
+
else if (part === "minute") next.setMinutes(amount);
|
|
380
|
+
else next.setSeconds(amount);
|
|
381
|
+
valueState.set((0, import_date.formatDate)(next, valueFormat.value));
|
|
382
|
+
}
|
|
383
|
+
function confirm() {
|
|
384
|
+
commitInput();
|
|
385
|
+
close();
|
|
386
|
+
}
|
|
387
|
+
function goNow() {
|
|
388
|
+
if (isDisabled.value) return;
|
|
389
|
+
valueState.set((0, import_date.formatDate)(/* @__PURE__ */ new Date(), valueFormat.value));
|
|
390
|
+
close();
|
|
391
|
+
}
|
|
392
|
+
function getTimeListProps(part) {
|
|
393
|
+
const label = part === "hour" ? "\u9009\u62E9\u5C0F\u65F6" : part === "minute" ? "\u9009\u62E9\u5206\u949F" : "\u9009\u62E9\u79D2";
|
|
394
|
+
return { role: "listbox", "aria-label": label, "data-part": `time-${part}` };
|
|
395
|
+
}
|
|
396
|
+
function getTimeOptionProps(part, amount) {
|
|
397
|
+
const isSelected = timeParts.value[part] === amount;
|
|
398
|
+
return {
|
|
399
|
+
role: "option",
|
|
400
|
+
"aria-selected": isSelected,
|
|
401
|
+
"data-selected": isSelected ? "" : void 0,
|
|
402
|
+
"data-value": amount
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
function clear() {
|
|
406
|
+
draft.value = null;
|
|
407
|
+
valueState.set(null);
|
|
408
|
+
}
|
|
409
|
+
function goToday() {
|
|
410
|
+
selectDate(/* @__PURE__ */ new Date());
|
|
411
|
+
}
|
|
412
|
+
function setPanel(next) {
|
|
413
|
+
panel.value = next;
|
|
414
|
+
if (next !== "date") focusedDate.value = panelDate.value;
|
|
415
|
+
}
|
|
416
|
+
function shiftView(unit, delta) {
|
|
417
|
+
const months = unit === "month" ? 1 : unit === "year" ? 12 : 120;
|
|
418
|
+
panelDate.value = (0, import_date.addMonths)(panelDate.value, delta * months);
|
|
419
|
+
focusedDate.value = (0, import_date.addMonths)(focusedDate.value, delta * months);
|
|
420
|
+
}
|
|
421
|
+
function moveFocus(move) {
|
|
422
|
+
syncView((0, import_date.resolveDateMove)(focusedDate.value, move));
|
|
423
|
+
}
|
|
424
|
+
function commitMonth(date) {
|
|
425
|
+
syncView(date);
|
|
426
|
+
panel.value = "date";
|
|
427
|
+
}
|
|
428
|
+
function commitYear(date) {
|
|
429
|
+
const current = focusedDate.value;
|
|
430
|
+
const next = (0, import_date.addMonths)(new Date(date.getFullYear(), 0, current.getDate()), current.getMonth());
|
|
431
|
+
syncView(next);
|
|
432
|
+
panel.value = "month";
|
|
433
|
+
}
|
|
434
|
+
function commitFocused() {
|
|
435
|
+
if (panel.value === "date") {
|
|
436
|
+
selectDate(focusedDate.value);
|
|
437
|
+
if (showTime.value) close();
|
|
438
|
+
} else if (panel.value === "month") commitMonth(focusedDate.value);
|
|
439
|
+
else commitYear(focusedDate.value);
|
|
440
|
+
}
|
|
441
|
+
function commitInput() {
|
|
442
|
+
if (draft.value === null) return;
|
|
443
|
+
const text = draft.value.trim();
|
|
444
|
+
draft.value = null;
|
|
445
|
+
if (text === "") {
|
|
446
|
+
valueState.set(null);
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
const parsed = (0, import_date.parseDate)(text, format.value);
|
|
450
|
+
if (!parsed || isDateDisabled(parsed)) return;
|
|
451
|
+
valueState.set((0, import_date.formatDate)(parsed, valueFormat.value));
|
|
452
|
+
if (isOpen.value) syncView(parsed);
|
|
453
|
+
}
|
|
454
|
+
function onInputInput(event) {
|
|
455
|
+
if (isDisabled.value) return;
|
|
456
|
+
const target = event.target;
|
|
457
|
+
if (target instanceof HTMLInputElement) draft.value = target.value;
|
|
458
|
+
}
|
|
459
|
+
function onInputBlur() {
|
|
460
|
+
commitInput();
|
|
461
|
+
}
|
|
462
|
+
function onInputFocus() {
|
|
463
|
+
if (skipFocusOpen) {
|
|
464
|
+
skipFocusOpen = false;
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
if (!isDisabled.value && !isOpen.value) open();
|
|
468
|
+
}
|
|
469
|
+
function onInputClick() {
|
|
470
|
+
if (!isDisabled.value && !isOpen.value) open();
|
|
471
|
+
}
|
|
472
|
+
function onInputKeydown(event) {
|
|
473
|
+
if (isDisabled.value) return;
|
|
474
|
+
if (!isOpen.value && event.key === "Enter" && draft.value !== null) {
|
|
475
|
+
event.preventDefault();
|
|
476
|
+
commitInput();
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
const intent = (0, import_date.resolveDatePickerKeyIntent)({
|
|
480
|
+
key: event.key,
|
|
481
|
+
open: isOpen.value,
|
|
482
|
+
panel: panel.value,
|
|
483
|
+
focusedDate: focusedDate.value,
|
|
484
|
+
firstDayOfWeek: firstDayOfWeek.value,
|
|
485
|
+
hasModifierKey: event.ctrlKey || event.altKey || event.metaKey
|
|
486
|
+
});
|
|
487
|
+
if (intent.kind === "none") return;
|
|
488
|
+
if (intent.kind === "tab-out") {
|
|
489
|
+
close();
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
event.preventDefault();
|
|
493
|
+
if (intent.kind === "open") open();
|
|
494
|
+
else if (intent.kind === "close") close();
|
|
495
|
+
else if (intent.kind === "move") moveFocus(intent.move);
|
|
496
|
+
else if (intent.kind === "commit") {
|
|
497
|
+
if (draft.value !== null) {
|
|
498
|
+
commitInput();
|
|
499
|
+
close();
|
|
500
|
+
} else {
|
|
501
|
+
commitFocused();
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
function onCellPointerDown(event) {
|
|
506
|
+
event.preventDefault();
|
|
507
|
+
}
|
|
508
|
+
function onCellClick(date, kind) {
|
|
509
|
+
if (isDisabled.value) return;
|
|
510
|
+
if (kind === "date") selectDate(date);
|
|
511
|
+
else if (kind === "month") commitMonth(date);
|
|
512
|
+
else commitYear(date);
|
|
513
|
+
}
|
|
514
|
+
function getTriggerProps() {
|
|
515
|
+
const labelledby = (0, import_vue5.toValue)(options.ariaLabelledby);
|
|
516
|
+
const describedby = (0, import_vue5.toValue)(options.ariaDescribedby);
|
|
517
|
+
return {
|
|
518
|
+
id: triggerId,
|
|
519
|
+
role: "combobox",
|
|
520
|
+
"aria-haspopup": "dialog",
|
|
521
|
+
"aria-expanded": isOpen.value,
|
|
522
|
+
"aria-controls": contentId,
|
|
523
|
+
// 面板被 portal 到 body,不是输入框的 DOM 后代;打开时显式声明所有权,
|
|
524
|
+
// 否则读屏拒绝播报 aria-activedescendant 指向的格子。与 Select 同一条约束。
|
|
525
|
+
"aria-owns": isOpen.value ? contentId : void 0,
|
|
526
|
+
"aria-activedescendant": isOpen.value ? getCellId(focusedDate.value, panel.value) : void 0,
|
|
527
|
+
"aria-autocomplete": "none",
|
|
528
|
+
"aria-disabled": isDisabled.value || void 0,
|
|
529
|
+
"aria-labelledby": labelledby || void 0,
|
|
530
|
+
"aria-describedby": describedby || void 0,
|
|
531
|
+
"data-state": isOpen.value ? "open" : "closed",
|
|
532
|
+
"data-disabled": isDisabled.value ? "" : void 0,
|
|
533
|
+
disabled: isDisabled.value || void 0,
|
|
534
|
+
autocomplete: "off",
|
|
535
|
+
name: (0, import_vue5.toValue)(options.name),
|
|
536
|
+
form: (0, import_vue5.toValue)(options.form)
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
function getContentProps() {
|
|
540
|
+
return {
|
|
541
|
+
id: contentId,
|
|
542
|
+
role: "dialog",
|
|
543
|
+
"aria-labelledby": (0, import_vue5.toValue)(options.ariaLabelledby) || triggerId,
|
|
544
|
+
tabindex: -1,
|
|
545
|
+
"data-state": isOpen.value ? "open" : "closed",
|
|
546
|
+
"data-panel": panel.value
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
function getGridProps(kind) {
|
|
550
|
+
const label = kind === "date" ? headerLabel.value : kind === "month" ? "\u9009\u62E9\u6708\u4EFD" : `${decadeLabel.value} \u9009\u62E9\u5E74\u4EFD`;
|
|
551
|
+
return { role: "grid", "aria-label": label };
|
|
552
|
+
}
|
|
553
|
+
function getCellProps(date, kind) {
|
|
554
|
+
const selected = selectedDate.value;
|
|
555
|
+
const focused = focusedDate.value;
|
|
556
|
+
const isSelected = kind === "date" ? selected !== null && (0, import_date.isSameDay)(selected, date) : kind === "month" ? selected !== null && (0, import_date.isSameMonth)(selected, date) : selected !== null && selected.getFullYear() === date.getFullYear();
|
|
557
|
+
const isFocused = kind === "date" ? (0, import_date.isSameDay)(focused, date) : kind === "month" ? (0, import_date.isSameMonth)(focused, date) : focused.getFullYear() === date.getFullYear();
|
|
558
|
+
const state = kind === "date" ? getCellState(date) : null;
|
|
559
|
+
const isDisabledCell = state ? state.disabled : false;
|
|
560
|
+
let isOutside = false;
|
|
561
|
+
if (state) {
|
|
562
|
+
isOutside = !state.inMonth;
|
|
563
|
+
} else if (kind === "year") {
|
|
564
|
+
const decadeStart = Math.floor(panelDate.value.getFullYear() / 10) * 10;
|
|
565
|
+
isOutside = date.getFullYear() < decadeStart || date.getFullYear() >= decadeStart + 10;
|
|
566
|
+
}
|
|
567
|
+
return {
|
|
568
|
+
id: getCellId(date, kind),
|
|
569
|
+
role: "gridcell",
|
|
570
|
+
"aria-selected": isSelected,
|
|
571
|
+
"aria-disabled": isDisabledCell || void 0,
|
|
572
|
+
// 日期格子只渲染「几号」,读屏需要完整日期才有意义;月 / 年格子的文本自足。
|
|
573
|
+
"aria-label": kind === "date" ? (0, import_date.formatDate)(date, "YYYY\u5E74M\u6708D\u65E5") : void 0,
|
|
574
|
+
"data-focused": isFocused ? "" : void 0,
|
|
575
|
+
"data-selected": isSelected ? "" : void 0,
|
|
576
|
+
"data-disabled": isDisabledCell ? "" : void 0,
|
|
577
|
+
"data-today": state?.today ? "" : void 0,
|
|
578
|
+
"data-outside": isOutside ? "" : void 0,
|
|
579
|
+
"data-value": (0, import_date.formatDate)(date, DEFAULT_VALUE_FORMAT)
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
function setTriggerElement(node) {
|
|
583
|
+
floating.referenceRef.value = node instanceof HTMLElement ? node : null;
|
|
584
|
+
}
|
|
585
|
+
function setContentElement(node) {
|
|
586
|
+
floating.floatingRef.value = node instanceof HTMLElement ? node : null;
|
|
587
|
+
}
|
|
588
|
+
function handleDocumentPointerDown(event) {
|
|
589
|
+
const target = event.target;
|
|
590
|
+
if (!(target instanceof Node)) return;
|
|
591
|
+
const trigger = floating.referenceRef.value;
|
|
592
|
+
const content = floating.floatingRef.value;
|
|
593
|
+
if (trigger?.contains(target) || content?.contains(target)) return;
|
|
594
|
+
commitInput();
|
|
595
|
+
close();
|
|
596
|
+
}
|
|
597
|
+
(0, import_vue5.watch)(
|
|
598
|
+
isOpen,
|
|
599
|
+
(open2) => {
|
|
600
|
+
if (!isBrowser) return;
|
|
601
|
+
document.removeEventListener("pointerdown", handleDocumentPointerDown, true);
|
|
602
|
+
if (open2) {
|
|
603
|
+
document.addEventListener("pointerdown", handleDocumentPointerDown, true);
|
|
604
|
+
} else {
|
|
605
|
+
draft.value = null;
|
|
606
|
+
panel.value = "date";
|
|
607
|
+
}
|
|
608
|
+
},
|
|
609
|
+
{ immediate: true }
|
|
610
|
+
);
|
|
611
|
+
const initialValue = value.value;
|
|
612
|
+
useFormResetListener(
|
|
613
|
+
floating.referenceRef,
|
|
614
|
+
() => {
|
|
615
|
+
valueState.set(initialValue);
|
|
616
|
+
draft.value = null;
|
|
617
|
+
panel.value = "date";
|
|
618
|
+
syncView(
|
|
619
|
+
initialValue ? (0, import_date.parseDate)(initialValue, valueFormat.value) ?? /* @__PURE__ */ new Date() : /* @__PURE__ */ new Date()
|
|
620
|
+
);
|
|
621
|
+
},
|
|
622
|
+
options.form
|
|
623
|
+
);
|
|
624
|
+
const contentStyle = (0, import_vue5.computed)(() => ({ ...floating.floatingStyle.value }));
|
|
625
|
+
(0, import_vue5.onScopeDispose)(() => {
|
|
626
|
+
if (isBrowser) document.removeEventListener("pointerdown", handleDocumentPointerDown, true);
|
|
627
|
+
});
|
|
628
|
+
return {
|
|
629
|
+
value,
|
|
630
|
+
setValue: valueState.set,
|
|
631
|
+
selectedDate,
|
|
632
|
+
isOpen,
|
|
633
|
+
open,
|
|
634
|
+
close,
|
|
635
|
+
panel: (0, import_vue5.computed)(() => panel.value),
|
|
636
|
+
setPanel,
|
|
637
|
+
panelDate: (0, import_vue5.computed)(() => panelDate.value),
|
|
638
|
+
focusedDate: (0, import_vue5.computed)(() => focusedDate.value),
|
|
639
|
+
dateCells,
|
|
640
|
+
monthCells,
|
|
641
|
+
yearCells,
|
|
642
|
+
weekdayLabels,
|
|
643
|
+
headerLabel,
|
|
644
|
+
decadeLabel,
|
|
645
|
+
displayText,
|
|
646
|
+
isTodayDisabled,
|
|
647
|
+
isDateDisabled,
|
|
648
|
+
getCellState,
|
|
649
|
+
selectDate,
|
|
650
|
+
clear,
|
|
651
|
+
goToday,
|
|
652
|
+
showTime,
|
|
653
|
+
timeParts,
|
|
654
|
+
setTimePart,
|
|
655
|
+
confirm,
|
|
656
|
+
goNow,
|
|
657
|
+
getTimeListProps,
|
|
658
|
+
getTimeOptionProps,
|
|
659
|
+
moveFocus,
|
|
660
|
+
commitFocused,
|
|
661
|
+
shiftView,
|
|
662
|
+
onInputInput,
|
|
663
|
+
onInputKeydown,
|
|
664
|
+
onInputBlur,
|
|
665
|
+
onInputFocus,
|
|
666
|
+
onInputClick,
|
|
667
|
+
onCellPointerDown,
|
|
668
|
+
onCellClick,
|
|
669
|
+
getTriggerProps,
|
|
670
|
+
getContentProps,
|
|
671
|
+
getGridProps,
|
|
672
|
+
getCellProps,
|
|
673
|
+
getCellId,
|
|
674
|
+
setTriggerElement,
|
|
675
|
+
setContentElement,
|
|
676
|
+
floating,
|
|
677
|
+
contentStyle
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
681
|
+
0 && (module.exports = {
|
|
682
|
+
useDatePicker
|
|
683
|
+
});
|
|
684
|
+
//# sourceMappingURL=index.cjs.map
|