@agile-plus/headless 0.1.1 → 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.
Files changed (231) hide show
  1. package/README.md +24 -17
  2. package/dist/index.cjs +4163 -223
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +33 -0
  5. package/dist/index.d.ts +33 -0
  6. package/dist/index.js +4258 -216
  7. package/dist/index.js.map +1 -1
  8. package/dist/types-BxsQI7P5.d.cts +93 -0
  9. package/dist/types-BxsQI7P5.d.ts +93 -0
  10. package/dist/types-zpeY0yvD.d.cts +73 -0
  11. package/dist/types-zpeY0yvD.d.ts +73 -0
  12. package/dist/useAccordion/index.cjs +149 -0
  13. package/dist/useAccordion/index.cjs.map +1 -0
  14. package/dist/useAccordion/index.d.cts +119 -0
  15. package/dist/useAccordion/index.d.ts +119 -0
  16. package/dist/useAccordion/index.js +128 -0
  17. package/dist/useAccordion/index.js.map +1 -0
  18. package/dist/useAvatar/index.cjs +135 -0
  19. package/dist/useAvatar/index.cjs.map +1 -0
  20. package/dist/useAvatar/index.d.cts +120 -0
  21. package/dist/useAvatar/index.d.ts +120 -0
  22. package/dist/useAvatar/index.js +106 -0
  23. package/dist/useAvatar/index.js.map +1 -0
  24. package/dist/useCheckbox/index.cjs +3 -1
  25. package/dist/useCheckbox/index.cjs.map +1 -1
  26. package/dist/useCheckbox/index.js +3 -1
  27. package/dist/useCheckbox/index.js.map +1 -1
  28. package/dist/useCollapsible/index.cjs +10 -0
  29. package/dist/useCollapsible/index.cjs.map +1 -1
  30. package/dist/useCollapsible/index.js +11 -1
  31. package/dist/useCollapsible/index.js.map +1 -1
  32. package/dist/useDatePicker/index.cjs +684 -0
  33. package/dist/useDatePicker/index.cjs.map +1 -0
  34. package/dist/useDatePicker/index.d.cts +191 -0
  35. package/dist/useDatePicker/index.d.ts +191 -0
  36. package/dist/useDatePicker/index.js +671 -0
  37. package/dist/useDatePicker/index.js.map +1 -0
  38. package/dist/useDateRangePicker/index.cjs +614 -0
  39. package/dist/useDateRangePicker/index.cjs.map +1 -0
  40. package/dist/useDateRangePicker/index.d.cts +159 -0
  41. package/dist/useDateRangePicker/index.d.ts +159 -0
  42. package/dist/useDateRangePicker/index.js +601 -0
  43. package/dist/useDateRangePicker/index.js.map +1 -0
  44. package/dist/useDialog/index.cjs.map +1 -1
  45. package/dist/useDialog/index.js.map +1 -1
  46. package/dist/useDropdownMenu/index.cjs +468 -0
  47. package/dist/useDropdownMenu/index.cjs.map +1 -0
  48. package/dist/useDropdownMenu/index.d.cts +73 -0
  49. package/dist/useDropdownMenu/index.d.ts +73 -0
  50. package/dist/useDropdownMenu/index.js +441 -0
  51. package/dist/useDropdownMenu/index.js.map +1 -0
  52. package/dist/useEllipsis/index.cjs +181 -0
  53. package/dist/useEllipsis/index.cjs.map +1 -0
  54. package/dist/useEllipsis/index.d.cts +67 -0
  55. package/dist/useEllipsis/index.d.ts +67 -0
  56. package/dist/useEllipsis/index.js +162 -0
  57. package/dist/useEllipsis/index.js.map +1 -0
  58. package/dist/useFloating/index.cjs +177 -0
  59. package/dist/useFloating/index.cjs.map +1 -0
  60. package/dist/useFloating/index.d.cts +21 -0
  61. package/dist/useFloating/index.d.ts +21 -0
  62. package/dist/useFloating/index.js +150 -0
  63. package/dist/useFloating/index.js.map +1 -0
  64. package/dist/useFormControl/index.cjs +5 -0
  65. package/dist/useFormControl/index.cjs.map +1 -1
  66. package/dist/useFormControl/index.js +5 -0
  67. package/dist/useFormControl/index.js.map +1 -1
  68. package/dist/useInput/index.cjs +192 -0
  69. package/dist/useInput/index.cjs.map +1 -0
  70. package/dist/useInput/index.d.cts +41 -0
  71. package/dist/useInput/index.d.ts +41 -0
  72. package/dist/useInput/index.js +165 -0
  73. package/dist/useInput/index.js.map +1 -0
  74. package/dist/useKeepMounted/index.cjs +44 -0
  75. package/dist/useKeepMounted/index.cjs.map +1 -0
  76. package/dist/useKeepMounted/index.d.cts +45 -0
  77. package/dist/useKeepMounted/index.d.ts +45 -0
  78. package/dist/useKeepMounted/index.js +17 -0
  79. package/dist/useKeepMounted/index.js.map +1 -0
  80. package/dist/useMenu/index.cjs +438 -0
  81. package/dist/useMenu/index.cjs.map +1 -0
  82. package/dist/useMenu/index.d.cts +134 -0
  83. package/dist/useMenu/index.d.ts +134 -0
  84. package/dist/useMenu/index.js +419 -0
  85. package/dist/useMenu/index.js.map +1 -0
  86. package/dist/usePagination/index.cjs +113 -0
  87. package/dist/usePagination/index.cjs.map +1 -0
  88. package/dist/usePagination/index.d.cts +139 -0
  89. package/dist/usePagination/index.d.ts +139 -0
  90. package/dist/usePagination/index.js +95 -0
  91. package/dist/usePagination/index.js.map +1 -0
  92. package/dist/usePopover/index.cjs +312 -0
  93. package/dist/usePopover/index.cjs.map +1 -0
  94. package/dist/usePopover/index.d.cts +71 -0
  95. package/dist/usePopover/index.d.ts +71 -0
  96. package/dist/usePopover/index.js +285 -0
  97. package/dist/usePopover/index.js.map +1 -0
  98. package/dist/useSelect/index.cjs +729 -0
  99. package/dist/useSelect/index.cjs.map +1 -0
  100. package/dist/useSelect/index.d.cts +193 -0
  101. package/dist/useSelect/index.d.ts +193 -0
  102. package/dist/useSelect/index.js +710 -0
  103. package/dist/useSelect/index.js.map +1 -0
  104. package/dist/useSplitter/index.cjs +558 -0
  105. package/dist/useSplitter/index.cjs.map +1 -0
  106. package/dist/useSplitter/index.d.cts +307 -0
  107. package/dist/useSplitter/index.d.ts +307 -0
  108. package/dist/useSplitter/index.js +541 -0
  109. package/dist/useSplitter/index.js.map +1 -0
  110. package/dist/useSwitch/index.cjs +4 -1
  111. package/dist/useSwitch/index.cjs.map +1 -1
  112. package/dist/useSwitch/index.js +4 -1
  113. package/dist/useSwitch/index.js.map +1 -1
  114. package/dist/useTable/index.cjs +308 -0
  115. package/dist/useTable/index.cjs.map +1 -0
  116. package/dist/useTable/index.d.cts +242 -0
  117. package/dist/useTable/index.d.ts +242 -0
  118. package/dist/useTable/index.js +301 -0
  119. package/dist/useTable/index.js.map +1 -0
  120. package/dist/useTabs/index.cjs +13 -4
  121. package/dist/useTabs/index.cjs.map +1 -1
  122. package/dist/useTabs/index.d.cts +5 -1
  123. package/dist/useTabs/index.d.ts +5 -1
  124. package/dist/useTabs/index.js +13 -4
  125. package/dist/useTabs/index.js.map +1 -1
  126. package/dist/useTextControl-Dcq0GFmg.d.cts +63 -0
  127. package/dist/useTextControl-Dcq0GFmg.d.ts +63 -0
  128. package/dist/useTextarea/index.cjs +186 -0
  129. package/dist/useTextarea/index.cjs.map +1 -0
  130. package/dist/useTextarea/index.d.cts +30 -0
  131. package/dist/useTextarea/index.d.ts +30 -0
  132. package/dist/useTextarea/index.js +159 -0
  133. package/dist/useTextarea/index.js.map +1 -0
  134. package/dist/useToast/index.cjs +27 -20
  135. package/dist/useToast/index.cjs.map +1 -1
  136. package/dist/useToast/index.js +27 -20
  137. package/dist/useToast/index.js.map +1 -1
  138. package/dist/useToastViewport/index.cjs +1 -3
  139. package/dist/useToastViewport/index.cjs.map +1 -1
  140. package/dist/useToastViewport/index.js +1 -3
  141. package/dist/useToastViewport/index.js.map +1 -1
  142. package/dist/useTooltip/index.cjs +357 -0
  143. package/dist/useTooltip/index.cjs.map +1 -0
  144. package/dist/useTooltip/index.d.cts +81 -0
  145. package/dist/useTooltip/index.d.ts +81 -0
  146. package/dist/useTooltip/index.js +338 -0
  147. package/dist/useTooltip/index.js.map +1 -0
  148. package/dist/useVirtualList/index.cjs +308 -0
  149. package/dist/useVirtualList/index.cjs.map +1 -0
  150. package/dist/useVirtualList/index.d.cts +31 -0
  151. package/dist/useVirtualList/index.d.ts +31 -0
  152. package/dist/useVirtualList/index.js +288 -0
  153. package/dist/useVirtualList/index.js.map +1 -0
  154. package/dist/useVirtualTree/index.cjs +520 -0
  155. package/dist/useVirtualTree/index.cjs.map +1 -0
  156. package/dist/useVirtualTree/index.d.cts +146 -0
  157. package/dist/useVirtualTree/index.d.ts +146 -0
  158. package/dist/useVirtualTree/index.js +511 -0
  159. package/dist/useVirtualTree/index.js.map +1 -0
  160. package/package.json +121 -2
  161. package/src/index.ts +38 -0
  162. package/src/useAccordion/index.ts +7 -0
  163. package/src/useAccordion/types.ts +118 -0
  164. package/src/useAccordion/useAccordion.ts +130 -0
  165. package/src/useAvatar/index.ts +14 -0
  166. package/src/useAvatar/types.ts +90 -0
  167. package/src/useAvatar/useAvatar.ts +39 -0
  168. package/src/useAvatar/useAvatarFallback.ts +62 -0
  169. package/src/useAvatar/useAvatarImage.ts +78 -0
  170. package/src/useCheckbox/useCheckbox.ts +4 -1
  171. package/src/useCollapsible/useCollapsible.ts +22 -1
  172. package/src/useDatePicker/index.ts +9 -0
  173. package/src/useDatePicker/types.ts +177 -0
  174. package/src/useDatePicker/useDatePicker.ts +688 -0
  175. package/src/useDateRangePicker/index.ts +8 -0
  176. package/src/useDateRangePicker/types.ts +146 -0
  177. package/src/useDateRangePicker/useDateRangePicker.ts +618 -0
  178. package/src/useDropdownMenu/index.ts +3 -0
  179. package/src/useDropdownMenu/types.ts +61 -0
  180. package/src/useDropdownMenu/useDropdownMenu.ts +322 -0
  181. package/src/useEllipsis/index.ts +3 -0
  182. package/src/useEllipsis/types.ts +51 -0
  183. package/src/useEllipsis/useEllipsis.ts +169 -0
  184. package/src/useFloating/index.ts +3 -0
  185. package/src/useFloating/types.ts +79 -0
  186. package/src/useFloating/useFloating.ts +199 -0
  187. package/src/useFormControl/useFormControl.ts +13 -0
  188. package/src/useInput/index.ts +3 -0
  189. package/src/useInput/types.ts +29 -0
  190. package/src/useInput/useInput.ts +40 -0
  191. package/src/useKeepMounted/index.ts +3 -0
  192. package/src/useKeepMounted/types.ts +29 -0
  193. package/src/useKeepMounted/useKeepMounted.ts +34 -0
  194. package/src/useMenu/index.ts +9 -0
  195. package/src/useMenu/types.ts +126 -0
  196. package/src/useMenu/useMenu.ts +504 -0
  197. package/src/usePagination/index.ts +3 -0
  198. package/src/usePagination/types.ts +137 -0
  199. package/src/usePagination/usePagination.ts +109 -0
  200. package/src/usePopover/index.ts +3 -0
  201. package/src/usePopover/types.ts +65 -0
  202. package/src/usePopover/usePopover.ts +157 -0
  203. package/src/useSelect/index.ts +9 -0
  204. package/src/useSelect/types.ts +184 -0
  205. package/src/useSelect/useSelect.ts +713 -0
  206. package/src/useSplitter/index.ts +10 -0
  207. package/src/useSplitter/types.ts +336 -0
  208. package/src/useSplitter/useSplitter.ts +648 -0
  209. package/src/useSplitter/useSplitterPanel.ts +106 -0
  210. package/src/useSwitch/useSwitch.ts +6 -1
  211. package/src/useTable/index.ts +3 -0
  212. package/src/useTable/types.ts +282 -0
  213. package/src/useTable/useTable.ts +407 -0
  214. package/src/useTabs/types.ts +5 -1
  215. package/src/useTabs/useTabs.ts +30 -6
  216. package/src/useTextarea/index.ts +3 -0
  217. package/src/useTextarea/types.ts +17 -0
  218. package/src/useTextarea/useTextarea.ts +34 -0
  219. package/src/useToast/useToast.ts +43 -26
  220. package/src/useToastViewport/useToastViewport.ts +10 -9
  221. package/src/useTooltip/index.ts +3 -0
  222. package/src/useTooltip/types.ts +72 -0
  223. package/src/useTooltip/useTooltip.ts +240 -0
  224. package/src/useVirtualList/index.ts +8 -0
  225. package/src/useVirtualList/types.ts +95 -0
  226. package/src/useVirtualList/useVirtualList.ts +478 -0
  227. package/src/useVirtualTree/index.ts +3 -0
  228. package/src/useVirtualTree/types.ts +179 -0
  229. package/src/useVirtualTree/useVirtualTree.ts +342 -0
  230. package/src/utils/useFocusTrap.ts +2 -0
  231. package/src/utils/useTextControl.ts +191 -0
@@ -0,0 +1,614 @@
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/useDateRangePicker/index.ts
21
+ var useDateRangePicker_exports = {};
22
+ __export(useDateRangePicker_exports, {
23
+ useDateRangePicker: () => useDateRangePicker
24
+ });
25
+ module.exports = __toCommonJS(useDateRangePicker_exports);
26
+
27
+ // src/useDateRangePicker/useDateRangePicker.ts
28
+ var import_vue4 = 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/env.ts
53
+ var isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
54
+ function isObserverAvailable(constructor) {
55
+ return typeof constructor === "function";
56
+ }
57
+
58
+ // src/useFloating/useFloating.ts
59
+ var import_vue3 = require("vue");
60
+ var import_floating = require("@agile-plus/primitives/floating");
61
+
62
+ // src/utils/useResizeObserver.ts
63
+ var import_vue2 = require("vue");
64
+ function useResizeObserver(onResize) {
65
+ let observer = null;
66
+ function observe(element) {
67
+ if (!element || !isBrowser || !isObserverAvailable(globalThis.ResizeObserver)) return;
68
+ observer ??= new ResizeObserver(() => onResize());
69
+ observer.observe(element);
70
+ }
71
+ function unobserve(element) {
72
+ observer?.unobserve(element);
73
+ }
74
+ function disconnect() {
75
+ observer?.disconnect();
76
+ observer = null;
77
+ }
78
+ (0, import_vue2.onScopeDispose)(disconnect);
79
+ return { observe, unobserve, disconnect };
80
+ }
81
+
82
+ // src/useFloating/useFloating.ts
83
+ function useFloating(options = {}) {
84
+ const referenceRef = (0, import_vue3.ref)(null);
85
+ const floatingRef = (0, import_vue3.ref)(null);
86
+ const x = (0, import_vue3.ref)(0);
87
+ const y = (0, import_vue3.ref)(0);
88
+ const placement = (0, import_vue3.ref)((0, import_vue3.toValue)(options.placement) ?? "bottom");
89
+ const arrow = (0, import_vue3.ref)(null);
90
+ const availableSpace = (0, import_vue3.ref)(null);
91
+ const isOpen = (0, import_vue3.computed)(() => (0, import_vue3.toValue)(options.open) ?? true);
92
+ const strategy = (0, import_vue3.computed)(() => options.strategy ?? "absolute");
93
+ let frame = null;
94
+ const resize = useResizeObserver(requestUpdate);
95
+ function requestUpdate() {
96
+ if (!isBrowser || frame !== null) return;
97
+ frame = window.requestAnimationFrame(() => {
98
+ frame = null;
99
+ measure();
100
+ });
101
+ }
102
+ function measure() {
103
+ const reference = referenceRef.value;
104
+ const floating = floatingRef.value;
105
+ if (!reference || !floating) return;
106
+ const referenceRect = reference.getBoundingClientRect();
107
+ const floatingRect = floating.getBoundingClientRect();
108
+ const boundaryRect = (0, import_vue3.toValue)(options.boundary)?.getBoundingClientRect();
109
+ const viewport = { width: window.innerWidth, height: window.innerHeight };
110
+ const scrollX = window.scrollX;
111
+ const scrollY = window.scrollY;
112
+ const snapshot = {
113
+ reference: {
114
+ x: referenceRect.x,
115
+ y: referenceRect.y,
116
+ width: referenceRect.width,
117
+ height: referenceRect.height
118
+ },
119
+ // 浮层自己的 x/y 是上一轮结果,传 0 以免本轮输出依赖历史状态。
120
+ floating: { x: 0, y: 0, width: floatingRect.width, height: floatingRect.height },
121
+ viewport,
122
+ ...boundaryRect ? {
123
+ boundary: {
124
+ x: boundaryRect.x,
125
+ y: boundaryRect.y,
126
+ width: boundaryRect.width,
127
+ height: boundaryRect.height
128
+ }
129
+ } : {}
130
+ };
131
+ const floatingOptions = {
132
+ placement: (0, import_vue3.toValue)(options.placement),
133
+ offset: options.offset,
134
+ flip: options.flip,
135
+ shift: options.shift,
136
+ padding: options.padding,
137
+ arrow: options.arrow
138
+ };
139
+ const result = (0, import_floating.computeFloatingPosition)(snapshot, floatingOptions);
140
+ x.value = strategy.value === "absolute" ? result.x + scrollX : result.x;
141
+ y.value = strategy.value === "absolute" ? result.y + scrollY : result.y;
142
+ placement.value = result.placement;
143
+ arrow.value = result.arrow;
144
+ availableSpace.value = (0, import_floating.computeAvailableSpace)(snapshot, result.placement, floatingOptions);
145
+ }
146
+ const floatingStyle = (0, import_vue3.computed)(() => ({
147
+ position: strategy.value,
148
+ left: 0,
149
+ top: 0,
150
+ transform: `translate(${x.value}px, ${y.value}px)`
151
+ }));
152
+ const arrowStyle = (0, import_vue3.computed)(() => {
153
+ const offset = arrow.value;
154
+ if (!offset) return {};
155
+ return offset.x !== null ? { position: "absolute", left: `${offset.x}px` } : { position: "absolute", top: `${offset.y}px` };
156
+ });
157
+ function attach() {
158
+ window.addEventListener("scroll", requestUpdate, true);
159
+ window.addEventListener("resize", requestUpdate);
160
+ resize.observe(referenceRef.value);
161
+ resize.observe(floatingRef.value);
162
+ }
163
+ function detach() {
164
+ if (!isBrowser) return;
165
+ window.removeEventListener("scroll", requestUpdate, true);
166
+ window.removeEventListener("resize", requestUpdate);
167
+ resize.disconnect();
168
+ }
169
+ (0, import_vue3.watch)(
170
+ [isOpen, referenceRef, floatingRef],
171
+ ([open]) => {
172
+ detach();
173
+ if (!isBrowser || !open) return;
174
+ attach();
175
+ void (0, import_vue3.nextTick)(measure);
176
+ },
177
+ { immediate: true }
178
+ );
179
+ (0, import_vue3.onScopeDispose)(() => {
180
+ detach();
181
+ if (frame !== null && isBrowser) {
182
+ window.cancelAnimationFrame(frame);
183
+ frame = null;
184
+ }
185
+ });
186
+ return {
187
+ referenceRef,
188
+ floatingRef,
189
+ x: (0, import_vue3.computed)(() => x.value),
190
+ y: (0, import_vue3.computed)(() => y.value),
191
+ placement: (0, import_vue3.computed)(() => placement.value),
192
+ availableSpace: (0, import_vue3.computed)(() => availableSpace.value),
193
+ floatingStyle,
194
+ arrowStyle,
195
+ update: requestUpdate
196
+ };
197
+ }
198
+
199
+ // src/useDateRangePicker/useDateRangePicker.ts
200
+ var DEFAULT_OFFSET = 4;
201
+ var DEFAULT_PADDING = 8;
202
+ var DEFAULT_VALUE_FORMAT = "YYYY-MM-DD";
203
+ var DEFAULT_FIRST_DAY_OF_WEEK = 1;
204
+ var DAYS_PER_WEEK = 7;
205
+ function useDateRangePicker(options = {}) {
206
+ const uid = (0, import_vue4.useId)();
207
+ const triggerIds = [`date-range-trigger-${uid}-0`, `date-range-trigger-${uid}-1`];
208
+ const contentId = `date-range-content-${uid}`;
209
+ const valueFormat = options.valueFormat ?? DEFAULT_VALUE_FORMAT;
210
+ const format = options.format ?? DEFAULT_VALUE_FORMAT;
211
+ const valueState = useControllable({
212
+ value: () => (0, import_vue4.toValue)(options.modelValue),
213
+ defaultValue: options.defaultValue ?? null,
214
+ onChange: (next) => options.onValueChange?.(next)
215
+ });
216
+ const openState = useControllable({
217
+ value: () => (0, import_vue4.toValue)(options.open),
218
+ defaultValue: options.defaultOpen ?? false,
219
+ onChange: (next) => options.onOpenChange?.(next)
220
+ });
221
+ const value = valueState.value;
222
+ const isOpen = openState.value;
223
+ const isDisabled = (0, import_vue4.computed)(() => (0, import_vue4.toValue)(options.disabled) === true);
224
+ const firstDayOfWeek = (0, import_vue4.computed)(() => {
225
+ const raw = (0, import_vue4.toValue)(options.firstDayOfWeek) ?? DEFAULT_FIRST_DAY_OF_WEEK;
226
+ return (raw % DAYS_PER_WEEK + DAYS_PER_WEEK) % DAYS_PER_WEEK;
227
+ });
228
+ const selectedRange = (0, import_vue4.computed)(() => {
229
+ const current = value.value;
230
+ if (!current) return null;
231
+ const start = (0, import_date.parseDate)(current[0], valueFormat);
232
+ const end = (0, import_date.parseDate)(current[1], valueFormat);
233
+ return start && end ? [start, end] : null;
234
+ });
235
+ const activeIndex = (0, import_vue4.ref)(0);
236
+ const draftRange = (0, import_vue4.ref)((0, import_date.emptyRangeDraft)());
237
+ const inputDrafts = (0, import_vue4.ref)([null, null]);
238
+ const hoverDate = (0, import_vue4.ref)(null);
239
+ let draftIsTyped = false;
240
+ const initialBase = selectedRange.value?.[0] ?? /* @__PURE__ */ new Date();
241
+ const panelDate = (0, import_vue4.ref)(startOfMonth(initialBase));
242
+ const focusedDate = (0, import_vue4.ref)((0, import_date.startOfDay)(initialBase));
243
+ const triggerElements = [null, null];
244
+ let skipFocusOpen = false;
245
+ const floating = useFloating({
246
+ placement: options.placement ?? "bottom-start",
247
+ offset: options.offset ?? DEFAULT_OFFSET,
248
+ flip: options.flip,
249
+ shift: options.shift,
250
+ padding: options.padding ?? DEFAULT_PADDING,
251
+ strategy: options.strategy,
252
+ open: isOpen
253
+ });
254
+ const rightPanelDate = (0, import_vue4.computed)(() => (0, import_date.addMonths)(panelDate.value, 1));
255
+ const awaitingEnd = (0, import_vue4.computed)(() => draftRange.value[0] !== null && draftRange.value[1] === null);
256
+ const displayTexts = (0, import_vue4.computed)(() => {
257
+ const picking = draftRange.value[0] !== null;
258
+ const committed = selectedRange.value;
259
+ function text(index) {
260
+ const draft = inputDrafts.value[index];
261
+ if (draft !== null) return draft;
262
+ if (picking) {
263
+ const pending = draftRange.value[index];
264
+ return pending ? (0, import_date.formatDate)(pending, format) : "";
265
+ }
266
+ return committed ? (0, import_date.formatDate)(committed[index], format) : "";
267
+ }
268
+ return [text(0), text(1)];
269
+ });
270
+ const leftCells = (0, import_vue4.computed)(
271
+ () => (0, import_date.getCalendarGrid)({
272
+ year: panelDate.value.getFullYear(),
273
+ month: panelDate.value.getMonth(),
274
+ firstDayOfWeek: firstDayOfWeek.value
275
+ })
276
+ );
277
+ const rightCells = (0, import_vue4.computed)(
278
+ () => (0, import_date.getCalendarGrid)({
279
+ year: rightPanelDate.value.getFullYear(),
280
+ month: rightPanelDate.value.getMonth(),
281
+ firstDayOfWeek: firstDayOfWeek.value
282
+ })
283
+ );
284
+ const weekdayLabels = (0, import_vue4.computed)(() => (0, import_date.getWeekdayLabels)(firstDayOfWeek.value));
285
+ function startOfMonth(date) {
286
+ return new Date(date.getFullYear(), date.getMonth(), 1);
287
+ }
288
+ function isDateDisabled(date) {
289
+ if (isDisabled.value) return true;
290
+ return options.disabledDate ? options.disabledDate((0, import_date.startOfDay)(date)) : false;
291
+ }
292
+ function getCellState(date, side) {
293
+ const picking = draftRange.value[0] !== null;
294
+ const committed = selectedRange.value;
295
+ const start = picking ? draftRange.value[0] : committed?.[0] ?? null;
296
+ const end = picking ? draftRange.value[1] : committed?.[1] ?? null;
297
+ const hover = awaitingEnd.value ? hoverDate.value : null;
298
+ const highlight = (0, import_date.getRangeHighlight)({ date, start, end, hover });
299
+ const monthAnchor = side === "left" ? panelDate.value : rightPanelDate.value;
300
+ return {
301
+ selected: highlight.isStart || highlight.isEnd,
302
+ disabled: isDateDisabled(date),
303
+ today: (0, import_date.isSameDay)(/* @__PURE__ */ new Date(), date),
304
+ inMonth: (0, import_date.isSameMonth)(monthAnchor, date),
305
+ ...highlight
306
+ };
307
+ }
308
+ function getCellId(date, side) {
309
+ return `date-range-cell-${uid}-${side}-${(0, import_date.formatDate)(date, DEFAULT_VALUE_FORMAT)}`;
310
+ }
311
+ function open(initialActive = 0) {
312
+ if (isDisabled.value) return;
313
+ if (!draftIsTyped) draftRange.value = (0, import_date.emptyRangeDraft)();
314
+ inputDrafts.value = [null, null];
315
+ hoverDate.value = null;
316
+ const base = draftRange.value[0] ?? selectedRange.value?.[0] ?? /* @__PURE__ */ new Date();
317
+ panelDate.value = startOfMonth(base);
318
+ focusedDate.value = (0, import_date.startOfDay)(base);
319
+ activeIndex.value = initialActive;
320
+ openState.set(true);
321
+ }
322
+ function cleanupDrafts() {
323
+ if (!draftIsTyped) draftRange.value = (0, import_date.emptyRangeDraft)();
324
+ inputDrafts.value = [null, null];
325
+ hoverDate.value = null;
326
+ }
327
+ function close() {
328
+ const content = floating.floatingRef.value;
329
+ const active = isBrowser ? document.activeElement : null;
330
+ cleanupDrafts();
331
+ openState.set(false);
332
+ if (content && active instanceof Node && content.contains(active)) {
333
+ skipFocusOpen = true;
334
+ triggerElements[activeIndex.value]?.focus();
335
+ }
336
+ }
337
+ function selectRange(start, end) {
338
+ if (isDisabled.value) return;
339
+ const [orderedStart, orderedEnd] = start.getTime() <= end.getTime() ? [start, end] : [end, start];
340
+ if (isDateDisabled(orderedStart) || isDateDisabled(orderedEnd)) return;
341
+ draftRange.value = (0, import_date.emptyRangeDraft)();
342
+ draftIsTyped = false;
343
+ valueState.set([(0, import_date.formatDate)(orderedStart, valueFormat), (0, import_date.formatDate)(orderedEnd, valueFormat)]);
344
+ close();
345
+ }
346
+ function selectRangeByValue(start, end) {
347
+ const parsedStart = (0, import_date.parseDate)(start, valueFormat);
348
+ const parsedEnd = (0, import_date.parseDate)(end, valueFormat);
349
+ if (parsedStart && parsedEnd) selectRange(parsedStart, parsedEnd);
350
+ }
351
+ function pickDate(date) {
352
+ if (isDateDisabled(date)) return;
353
+ const result = (0, import_date.resolveRangePick)({ draft: draftRange.value, active: activeIndex.value, date });
354
+ if (result.done && result.draft[0] && result.draft[1]) {
355
+ selectRange(result.draft[0], result.draft[1]);
356
+ return;
357
+ }
358
+ draftRange.value = result.draft;
359
+ draftIsTyped = false;
360
+ hoverDate.value = null;
361
+ setActiveIndex(result.active);
362
+ }
363
+ function clear() {
364
+ draftRange.value = (0, import_date.emptyRangeDraft)();
365
+ draftIsTyped = false;
366
+ inputDrafts.value = [null, null];
367
+ hoverDate.value = null;
368
+ valueState.set(null);
369
+ }
370
+ function setActiveIndex(index) {
371
+ activeIndex.value = index;
372
+ triggerElements[index]?.focus();
373
+ }
374
+ function shiftView(unit, delta) {
375
+ const months = unit === "month" ? 1 : 12;
376
+ panelDate.value = (0, import_date.addMonths)(panelDate.value, delta * months);
377
+ focusedDate.value = (0, import_date.addMonths)(focusedDate.value, delta * months);
378
+ }
379
+ function moveFocus(move) {
380
+ const next = (0, import_date.resolveDateMove)(focusedDate.value, move);
381
+ focusedDate.value = next;
382
+ panelDate.value = startOfMonth(next);
383
+ }
384
+ function commitInput(index) {
385
+ const text = inputDrafts.value[index];
386
+ if (text === null) return;
387
+ inputDrafts.value = index === 0 ? [null, inputDrafts.value[1]] : [inputDrafts.value[0], null];
388
+ const trimmed = text.trim();
389
+ if (trimmed === "") {
390
+ clear();
391
+ return;
392
+ }
393
+ const parsed = (0, import_date.parseDate)(trimmed, format);
394
+ if (!parsed || isDateDisabled(parsed)) return;
395
+ const other = draftRange.value[1 - index] ?? selectedRange.value?.[1 - index] ?? null;
396
+ if (other) {
397
+ selectRange(parsed, other);
398
+ return;
399
+ }
400
+ draftRange.value = index === 0 ? [parsed, null] : [null, parsed];
401
+ draftIsTyped = true;
402
+ }
403
+ function onInputInput(index, event) {
404
+ if (isDisabled.value) return;
405
+ const target = event.target;
406
+ if (!(target instanceof HTMLInputElement)) return;
407
+ inputDrafts.value = index === 0 ? [target.value, inputDrafts.value[1]] : [inputDrafts.value[0], target.value];
408
+ }
409
+ function onInputBlur(index) {
410
+ commitInput(index);
411
+ }
412
+ function onInputFocus(index) {
413
+ if (skipFocusOpen) {
414
+ skipFocusOpen = false;
415
+ return;
416
+ }
417
+ activeIndex.value = index;
418
+ if (!isDisabled.value && !isOpen.value) open(index);
419
+ }
420
+ function onInputClick(index) {
421
+ if (!isDisabled.value && !isOpen.value) open(index);
422
+ }
423
+ function onInputKeydown(index, event) {
424
+ if (isDisabled.value) return;
425
+ if (event.key === "Tab" && isOpen.value) {
426
+ if (index === 0 && !event.shiftKey) {
427
+ event.preventDefault();
428
+ setActiveIndex(1);
429
+ return;
430
+ }
431
+ if (index === 1 && event.shiftKey) {
432
+ event.preventDefault();
433
+ setActiveIndex(0);
434
+ return;
435
+ }
436
+ close();
437
+ return;
438
+ }
439
+ if (!isOpen.value && event.key === "Enter" && inputDrafts.value[index] !== null) {
440
+ event.preventDefault();
441
+ commitInput(index);
442
+ return;
443
+ }
444
+ const intent = (0, import_date.resolveDatePickerKeyIntent)({
445
+ key: event.key,
446
+ open: isOpen.value,
447
+ panel: "date",
448
+ focusedDate: focusedDate.value,
449
+ firstDayOfWeek: firstDayOfWeek.value,
450
+ hasModifierKey: event.ctrlKey || event.altKey || event.metaKey
451
+ });
452
+ if (intent.kind === "none") return;
453
+ if (intent.kind === "tab-out") {
454
+ close();
455
+ return;
456
+ }
457
+ event.preventDefault();
458
+ if (intent.kind === "open") open(index);
459
+ else if (intent.kind === "close") {
460
+ draftIsTyped = false;
461
+ close();
462
+ } else if (intent.kind === "move") moveFocus(intent.move);
463
+ else if (intent.kind === "commit") pickDate(focusedDate.value);
464
+ }
465
+ function onCellPointerDown(event) {
466
+ event.preventDefault();
467
+ }
468
+ function onCellPointerEnter(date) {
469
+ if (awaitingEnd.value) hoverDate.value = date;
470
+ }
471
+ function onCellPointerLeave() {
472
+ hoverDate.value = null;
473
+ }
474
+ function getTriggerProps(index) {
475
+ const labelledby = (0, import_vue4.toValue)(options.ariaLabelledby);
476
+ const describedby = (0, import_vue4.toValue)(options.ariaDescribedby);
477
+ return {
478
+ id: triggerIds[index],
479
+ role: "combobox",
480
+ "aria-haspopup": "dialog",
481
+ "aria-expanded": isOpen.value,
482
+ "aria-controls": contentId,
483
+ "aria-owns": isOpen.value ? contentId : void 0,
484
+ // 焦点格只在活跃输入框上声明,两个 combobox 同时指向一个格子会让读屏重复播报。
485
+ "aria-activedescendant": isOpen.value && activeIndex.value === index ? getCellId(focusedDate.value, "left") : void 0,
486
+ "aria-autocomplete": "none",
487
+ "aria-disabled": isDisabled.value || void 0,
488
+ "aria-labelledby": labelledby || void 0,
489
+ "aria-describedby": describedby || void 0,
490
+ "data-state": isOpen.value ? "open" : "closed",
491
+ "data-disabled": isDisabled.value ? "" : void 0,
492
+ "data-active": isOpen.value && activeIndex.value === index ? "" : void 0,
493
+ disabled: isDisabled.value || void 0,
494
+ autocomplete: "off"
495
+ };
496
+ }
497
+ function getContentProps() {
498
+ return {
499
+ id: contentId,
500
+ role: "dialog",
501
+ "aria-labelledby": (0, import_vue4.toValue)(options.ariaLabelledby) || triggerIds[0],
502
+ tabindex: -1,
503
+ "data-state": isOpen.value ? "open" : "closed"
504
+ };
505
+ }
506
+ function getGridProps(side) {
507
+ const anchor = side === "left" ? panelDate.value : rightPanelDate.value;
508
+ return { role: "grid", "aria-label": (0, import_date.formatDate)(anchor, "YYYY\u5E74 M\u6708") };
509
+ }
510
+ function getCellProps(date, side) {
511
+ const state = getCellState(date, side);
512
+ return {
513
+ id: getCellId(date, side),
514
+ role: "gridcell",
515
+ "aria-selected": state.selected,
516
+ "aria-disabled": state.disabled || void 0,
517
+ "aria-label": (0, import_date.formatDate)(date, "YYYY\u5E74M\u6708D\u65E5"),
518
+ "data-focused": (0, import_date.isSameDay)(focusedDate.value, date) ? "" : void 0,
519
+ "data-selected": state.selected ? "" : void 0,
520
+ "data-range-start": state.isStart ? "" : void 0,
521
+ "data-range-end": state.isEnd ? "" : void 0,
522
+ "data-in-range": state.inRange ? "" : void 0,
523
+ "data-preview": state.inPreview ? "" : void 0,
524
+ "data-hover-end": state.isHoverEnd ? "" : void 0,
525
+ "data-disabled": state.disabled ? "" : void 0,
526
+ "data-today": state.today ? "" : void 0,
527
+ "data-outside": state.inMonth ? void 0 : "",
528
+ "data-value": (0, import_date.formatDate)(date, DEFAULT_VALUE_FORMAT)
529
+ };
530
+ }
531
+ function setTriggerElement(node, index) {
532
+ triggerElements[index] = node instanceof HTMLElement ? node : null;
533
+ }
534
+ function setControlElement(node) {
535
+ floating.referenceRef.value = node instanceof HTMLElement ? node : null;
536
+ }
537
+ function setContentElement(node) {
538
+ floating.floatingRef.value = node instanceof HTMLElement ? node : null;
539
+ }
540
+ function handleDocumentPointerDown(event) {
541
+ const target = event.target;
542
+ if (!(target instanceof Node)) return;
543
+ const control = floating.referenceRef.value;
544
+ const content = floating.floatingRef.value;
545
+ if (control?.contains(target) || content?.contains(target)) return;
546
+ commitInput(activeIndex.value);
547
+ close();
548
+ }
549
+ (0, import_vue4.watch)(
550
+ isOpen,
551
+ (open2) => {
552
+ if (!isBrowser) return;
553
+ document.removeEventListener("pointerdown", handleDocumentPointerDown, true);
554
+ if (open2) {
555
+ document.addEventListener("pointerdown", handleDocumentPointerDown, true);
556
+ } else {
557
+ cleanupDrafts();
558
+ }
559
+ },
560
+ { immediate: true }
561
+ );
562
+ const contentStyle = (0, import_vue4.computed)(() => ({ ...floating.floatingStyle.value }));
563
+ (0, import_vue4.onScopeDispose)(() => {
564
+ if (isBrowser) document.removeEventListener("pointerdown", handleDocumentPointerDown, true);
565
+ });
566
+ return {
567
+ value,
568
+ setValue: valueState.set,
569
+ selectedRange,
570
+ isOpen,
571
+ open,
572
+ close,
573
+ activeIndex: (0, import_vue4.computed)(() => activeIndex.value),
574
+ setActiveIndex,
575
+ panelDate: (0, import_vue4.computed)(() => panelDate.value),
576
+ rightPanelDate,
577
+ leftCells,
578
+ rightCells,
579
+ weekdayLabels,
580
+ focusedDate: (0, import_vue4.computed)(() => focusedDate.value),
581
+ displayTexts,
582
+ isDateDisabled,
583
+ getCellState,
584
+ pickDate,
585
+ selectRange,
586
+ selectRangeByValue,
587
+ clear,
588
+ shiftView,
589
+ moveFocus,
590
+ onInputInput,
591
+ onInputKeydown,
592
+ onInputBlur,
593
+ onInputFocus,
594
+ onInputClick,
595
+ onCellPointerDown,
596
+ onCellPointerEnter,
597
+ onCellPointerLeave,
598
+ getTriggerProps,
599
+ getContentProps,
600
+ getGridProps,
601
+ getCellProps,
602
+ getCellId,
603
+ setTriggerElement,
604
+ setControlElement,
605
+ setContentElement,
606
+ floating,
607
+ contentStyle
608
+ };
609
+ }
610
+ // Annotate the CommonJS export names for ESM import in node:
611
+ 0 && (module.exports = {
612
+ useDateRangePicker
613
+ });
614
+ //# sourceMappingURL=index.cjs.map