@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.
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,312 @@
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/usePopover/index.ts
21
+ var usePopover_exports = {};
22
+ __export(usePopover_exports, {
23
+ usePopover: () => usePopover
24
+ });
25
+ module.exports = __toCommonJS(usePopover_exports);
26
+
27
+ // src/usePopover/usePopover.ts
28
+ var import_vue4 = require("vue");
29
+
30
+ // src/utils/useControllable.ts
31
+ var import_vue = require("vue");
32
+ function useControllable(options) {
33
+ const controlled = (0, import_vue.computed)(() => (0, import_vue.toValue)(options.value));
34
+ const isControlled = (0, import_vue.computed)(() => controlled.value !== void 0);
35
+ const internal = (0, import_vue.shallowRef)(options.defaultValue);
36
+ const value = (0, import_vue.computed)(() => {
37
+ const current = controlled.value;
38
+ return current === void 0 ? internal.value : current;
39
+ });
40
+ function set(next) {
41
+ if (!isControlled.value) internal.value = next;
42
+ options.onChange?.(next);
43
+ }
44
+ function replace(next) {
45
+ if (isControlled.value) return;
46
+ internal.value = next;
47
+ }
48
+ return { value, isControlled, set, replace };
49
+ }
50
+
51
+ // src/utils/env.ts
52
+ var isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
53
+ function isObserverAvailable(constructor) {
54
+ return typeof constructor === "function";
55
+ }
56
+
57
+ // src/useFloating/useFloating.ts
58
+ var import_vue3 = require("vue");
59
+ var import_floating = require("@agile-plus/primitives/floating");
60
+
61
+ // src/utils/useResizeObserver.ts
62
+ var import_vue2 = require("vue");
63
+ function useResizeObserver(onResize) {
64
+ let observer = null;
65
+ function observe(element) {
66
+ if (!element || !isBrowser || !isObserverAvailable(globalThis.ResizeObserver)) return;
67
+ observer ??= new ResizeObserver(() => onResize());
68
+ observer.observe(element);
69
+ }
70
+ function unobserve(element) {
71
+ observer?.unobserve(element);
72
+ }
73
+ function disconnect() {
74
+ observer?.disconnect();
75
+ observer = null;
76
+ }
77
+ (0, import_vue2.onScopeDispose)(disconnect);
78
+ return { observe, unobserve, disconnect };
79
+ }
80
+
81
+ // src/useFloating/useFloating.ts
82
+ function useFloating(options = {}) {
83
+ const referenceRef = (0, import_vue3.ref)(null);
84
+ const floatingRef = (0, import_vue3.ref)(null);
85
+ const x = (0, import_vue3.ref)(0);
86
+ const y = (0, import_vue3.ref)(0);
87
+ const placement = (0, import_vue3.ref)((0, import_vue3.toValue)(options.placement) ?? "bottom");
88
+ const arrow = (0, import_vue3.ref)(null);
89
+ const availableSpace = (0, import_vue3.ref)(null);
90
+ const isOpen = (0, import_vue3.computed)(() => (0, import_vue3.toValue)(options.open) ?? true);
91
+ const strategy = (0, import_vue3.computed)(() => options.strategy ?? "absolute");
92
+ let frame = null;
93
+ const resize = useResizeObserver(requestUpdate);
94
+ function requestUpdate() {
95
+ if (!isBrowser || frame !== null) return;
96
+ frame = window.requestAnimationFrame(() => {
97
+ frame = null;
98
+ measure();
99
+ });
100
+ }
101
+ function measure() {
102
+ const reference = referenceRef.value;
103
+ const floating = floatingRef.value;
104
+ if (!reference || !floating) return;
105
+ const referenceRect = reference.getBoundingClientRect();
106
+ const floatingRect = floating.getBoundingClientRect();
107
+ const boundaryRect = (0, import_vue3.toValue)(options.boundary)?.getBoundingClientRect();
108
+ const viewport = { width: window.innerWidth, height: window.innerHeight };
109
+ const scrollX = window.scrollX;
110
+ const scrollY = window.scrollY;
111
+ const snapshot = {
112
+ reference: {
113
+ x: referenceRect.x,
114
+ y: referenceRect.y,
115
+ width: referenceRect.width,
116
+ height: referenceRect.height
117
+ },
118
+ // 浮层自己的 x/y 是上一轮结果,传 0 以免本轮输出依赖历史状态。
119
+ floating: { x: 0, y: 0, width: floatingRect.width, height: floatingRect.height },
120
+ viewport,
121
+ ...boundaryRect ? {
122
+ boundary: {
123
+ x: boundaryRect.x,
124
+ y: boundaryRect.y,
125
+ width: boundaryRect.width,
126
+ height: boundaryRect.height
127
+ }
128
+ } : {}
129
+ };
130
+ const floatingOptions = {
131
+ placement: (0, import_vue3.toValue)(options.placement),
132
+ offset: options.offset,
133
+ flip: options.flip,
134
+ shift: options.shift,
135
+ padding: options.padding,
136
+ arrow: options.arrow
137
+ };
138
+ const result = (0, import_floating.computeFloatingPosition)(snapshot, floatingOptions);
139
+ x.value = strategy.value === "absolute" ? result.x + scrollX : result.x;
140
+ y.value = strategy.value === "absolute" ? result.y + scrollY : result.y;
141
+ placement.value = result.placement;
142
+ arrow.value = result.arrow;
143
+ availableSpace.value = (0, import_floating.computeAvailableSpace)(snapshot, result.placement, floatingOptions);
144
+ }
145
+ const floatingStyle = (0, import_vue3.computed)(() => ({
146
+ position: strategy.value,
147
+ left: 0,
148
+ top: 0,
149
+ transform: `translate(${x.value}px, ${y.value}px)`
150
+ }));
151
+ const arrowStyle = (0, import_vue3.computed)(() => {
152
+ const offset = arrow.value;
153
+ if (!offset) return {};
154
+ return offset.x !== null ? { position: "absolute", left: `${offset.x}px` } : { position: "absolute", top: `${offset.y}px` };
155
+ });
156
+ function attach() {
157
+ window.addEventListener("scroll", requestUpdate, true);
158
+ window.addEventListener("resize", requestUpdate);
159
+ resize.observe(referenceRef.value);
160
+ resize.observe(floatingRef.value);
161
+ }
162
+ function detach() {
163
+ if (!isBrowser) return;
164
+ window.removeEventListener("scroll", requestUpdate, true);
165
+ window.removeEventListener("resize", requestUpdate);
166
+ resize.disconnect();
167
+ }
168
+ (0, import_vue3.watch)(
169
+ [isOpen, referenceRef, floatingRef],
170
+ ([open]) => {
171
+ detach();
172
+ if (!isBrowser || !open) return;
173
+ attach();
174
+ void (0, import_vue3.nextTick)(measure);
175
+ },
176
+ { immediate: true }
177
+ );
178
+ (0, import_vue3.onScopeDispose)(() => {
179
+ detach();
180
+ if (frame !== null && isBrowser) {
181
+ window.cancelAnimationFrame(frame);
182
+ frame = null;
183
+ }
184
+ });
185
+ return {
186
+ referenceRef,
187
+ floatingRef,
188
+ x: (0, import_vue3.computed)(() => x.value),
189
+ y: (0, import_vue3.computed)(() => y.value),
190
+ placement: (0, import_vue3.computed)(() => placement.value),
191
+ availableSpace: (0, import_vue3.computed)(() => availableSpace.value),
192
+ floatingStyle,
193
+ arrowStyle,
194
+ update: requestUpdate
195
+ };
196
+ }
197
+
198
+ // src/usePopover/usePopover.ts
199
+ function usePopover(options = {}) {
200
+ const uid = (0, import_vue4.useId)();
201
+ const triggerId = `popover-trigger-${uid}`;
202
+ const contentId = `popover-content-${uid}`;
203
+ const state = useControllable({
204
+ value: () => (0, import_vue4.toValue)(options.open),
205
+ defaultValue: options.defaultOpen ?? false,
206
+ onChange: (next) => options.onOpenChange?.(next)
207
+ });
208
+ const isOpen = state.value;
209
+ const floating = useFloating({
210
+ placement: options.placement ?? "bottom",
211
+ offset: options.offset ?? 8,
212
+ flip: options.flip,
213
+ shift: options.shift,
214
+ padding: options.padding ?? 8,
215
+ strategy: options.strategy,
216
+ arrow: options.arrow ?? { size: 8 },
217
+ open: isOpen
218
+ });
219
+ function open() {
220
+ state.set(true);
221
+ }
222
+ function close() {
223
+ const content = floating.floatingRef.value;
224
+ const active = isBrowser ? document.activeElement : null;
225
+ state.set(false);
226
+ if (content && active instanceof Node && content.contains(active)) {
227
+ floating.referenceRef.value?.focus();
228
+ }
229
+ }
230
+ function toggle() {
231
+ if (isOpen.value) close();
232
+ else open();
233
+ }
234
+ function onContentKeydown(event) {
235
+ if (event.key !== "Escape") return;
236
+ if (options.closeOnEscape === false) return;
237
+ event.preventDefault();
238
+ close();
239
+ }
240
+ function getTriggerProps() {
241
+ return {
242
+ id: triggerId,
243
+ "aria-haspopup": "dialog",
244
+ "aria-expanded": isOpen.value,
245
+ "aria-controls": isOpen.value ? contentId : void 0,
246
+ "data-state": isOpen.value ? "open" : "closed"
247
+ };
248
+ }
249
+ function getContentProps() {
250
+ return {
251
+ id: contentId,
252
+ role: "dialog",
253
+ "aria-labelledby": triggerId,
254
+ tabindex: -1,
255
+ "data-state": isOpen.value ? "open" : "closed"
256
+ };
257
+ }
258
+ function getCloseProps() {
259
+ return { type: "button" };
260
+ }
261
+ function setTriggerElement(node) {
262
+ floating.referenceRef.value = node instanceof HTMLElement ? node : null;
263
+ }
264
+ function setContentElement(node) {
265
+ floating.floatingRef.value = node instanceof HTMLElement ? node : null;
266
+ }
267
+ function handleDocumentPointerDown(event) {
268
+ const target = event.target;
269
+ if (!(target instanceof Node)) return;
270
+ const trigger = floating.referenceRef.value;
271
+ const content = floating.floatingRef.value;
272
+ if (trigger?.contains(target) || content?.contains(target)) return;
273
+ close();
274
+ }
275
+ (0, import_vue4.watch)(
276
+ isOpen,
277
+ (open2) => {
278
+ if (!isBrowser) return;
279
+ document.removeEventListener("pointerdown", handleDocumentPointerDown, true);
280
+ if (open2) {
281
+ document.addEventListener("pointerdown", handleDocumentPointerDown, true);
282
+ void (0, import_vue4.nextTick)(() => {
283
+ floating.floatingRef.value?.focus({ preventScroll: true });
284
+ });
285
+ }
286
+ },
287
+ { immediate: true }
288
+ );
289
+ (0, import_vue4.onScopeDispose)(() => {
290
+ if (isBrowser) document.removeEventListener("pointerdown", handleDocumentPointerDown, true);
291
+ });
292
+ return {
293
+ isOpen,
294
+ open,
295
+ close,
296
+ toggle,
297
+ triggerId,
298
+ contentId,
299
+ floating,
300
+ getTriggerProps,
301
+ getContentProps,
302
+ getCloseProps,
303
+ setTriggerElement,
304
+ setContentElement,
305
+ onContentKeydown
306
+ };
307
+ }
308
+ // Annotate the CommonJS export names for ESM import in node:
309
+ 0 && (module.exports = {
310
+ usePopover
311
+ });
312
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/usePopover/index.ts","../../src/usePopover/usePopover.ts","../../src/utils/useControllable.ts","../../src/utils/env.ts","../../src/useFloating/useFloating.ts","../../src/utils/useResizeObserver.ts"],"sourcesContent":["export type { UsePopoverOptions, UsePopoverReturn } from './types';\n\nexport { usePopover } from './usePopover';\n","import { nextTick, onScopeDispose, toValue, useId, watch } from 'vue';\n\nimport { useControllable } from '../utils/useControllable';\nimport { isBrowser } from '../utils/env';\nimport { useFloating } from '../useFloating';\n\nimport type { UsePopoverOptions, UsePopoverReturn } from './types';\n\n/**\n * Popover 的 Vue 适配。\n *\n * 非模态浮层:不锁滚动、不做焦点陷阱;打开时由 UI 层把焦点移进浮层,关闭时若焦点\n * 曾在浮层内则交还触发元素。外部指针按下与 Escape 关闭。\n *\n * 内容**懒渲染**:UI 层用 usePresence 的 v-if 驱动,关闭即卸载,打开才挂载;本层只\n * 持有开合状态与定位,不持有内容 DOM。\n */\nexport function usePopover(options: UsePopoverOptions = {}): UsePopoverReturn {\n const uid = useId();\n const triggerId = `popover-trigger-${uid}`;\n const contentId = `popover-content-${uid}`;\n\n const state = useControllable<boolean>({\n value: () => toValue(options.open),\n defaultValue: options.defaultOpen ?? false,\n onChange: (next) => options.onOpenChange?.(next),\n });\n\n const isOpen = state.value;\n\n const floating = useFloating({\n placement: options.placement ?? 'bottom',\n offset: options.offset ?? 8,\n flip: options.flip,\n shift: options.shift,\n padding: options.padding ?? 8,\n strategy: options.strategy,\n arrow: options.arrow ?? { size: 8 },\n open: isOpen,\n });\n\n function open(): void {\n state.set(true);\n }\n\n function close(): void {\n const content = floating.floatingRef.value;\n const active = isBrowser ? document.activeElement : null;\n\n state.set(false);\n\n // 焦点曾在浮层内才交还触发元素;外部点击关闭时不抢焦点。\n if (content && active instanceof Node && content.contains(active)) {\n floating.referenceRef.value?.focus();\n }\n }\n\n function toggle(): void {\n if (isOpen.value) close();\n else open();\n }\n\n function onContentKeydown(event: KeyboardEvent): void {\n if (event.key !== 'Escape') return;\n\n if (options.closeOnEscape === false) return;\n\n event.preventDefault();\n close();\n }\n\n function getTriggerProps(): Record<string, unknown> {\n return {\n id: triggerId,\n 'aria-haspopup': 'dialog',\n 'aria-expanded': isOpen.value,\n 'aria-controls': isOpen.value ? contentId : undefined,\n 'data-state': isOpen.value ? 'open' : 'closed',\n };\n }\n\n function getContentProps(): Record<string, unknown> {\n return {\n id: contentId,\n role: 'dialog',\n 'aria-labelledby': triggerId,\n tabindex: -1,\n 'data-state': isOpen.value ? 'open' : 'closed',\n };\n }\n\n function getCloseProps(): Record<string, unknown> {\n return { type: 'button' };\n }\n\n function setTriggerElement(node: unknown): void {\n floating.referenceRef.value = node instanceof HTMLElement ? node : null;\n }\n\n function setContentElement(node: unknown): void {\n floating.floatingRef.value = node instanceof HTMLElement ? node : null;\n }\n\n function handleDocumentPointerDown(event: PointerEvent): void {\n const target = event.target;\n\n if (!(target instanceof Node)) return;\n\n const trigger = floating.referenceRef.value;\n const content = floating.floatingRef.value;\n\n if (trigger?.contains(target) || content?.contains(target)) return;\n\n close();\n }\n\n watch(\n isOpen,\n (open) => {\n if (!isBrowser) return;\n\n document.removeEventListener('pointerdown', handleDocumentPointerDown, true);\n\n if (open) {\n document.addEventListener('pointerdown', handleDocumentPointerDown, true);\n\n // 打开后焦点移进浮层(非模态);懒渲染下内容下一拍才挂载,等 nextTick。\n // 必须 preventScroll:此刻 rAF 测量还没把浮层挪到正确坐标,元素首帧停在文档\n // 原点,默认 focus 会把它滚进视口,表现为页面滚到顶部。\n void nextTick(() => {\n floating.floatingRef.value?.focus({ preventScroll: true });\n });\n }\n },\n { immediate: true }\n );\n\n onScopeDispose(() => {\n if (isBrowser) document.removeEventListener('pointerdown', handleDocumentPointerDown, true);\n });\n\n return {\n isOpen,\n open,\n close,\n toggle,\n triggerId,\n contentId,\n floating,\n getTriggerProps,\n getContentProps,\n getCloseProps,\n setTriggerElement,\n setContentElement,\n onContentKeydown,\n };\n}\n","import { computed, shallowRef, toValue } from 'vue';\n\nimport type { ComputedRef, MaybeRefOrGetter } from 'vue';\n\n/**\n * 受控 / 非受控状态。\n *\n * 这是 Radix `useControllableState` 的对应物,也是本库所有带状态组件的真源判定入口。\n *\n * @template T 值类型。整体替换语义(数组也是换一个新数组而不是就地改),因此内部用\n * shallowRef:深响应会把值里嵌套的 Ref 拆包,而这个 hook 无法保证调用方传进来的形状。\n */\nexport interface UseControllableOptions<T> {\n /**\n * 受控值来源。\n *\n * **`undefined` 就是「未受控」的唯一判据**:封装层必须让 Boolean prop 缺省保持\n * undefined,被 cast 成 false 会让组件变成「受控且恒为该值」,非受控用法静默失效。\n */\n value?: MaybeRefOrGetter<T | undefined>;\n\n /** 非受控模式的初始值,必须由调用方给出(不提供隐式零值,避免各组件默认值漂移) */\n defaultValue: T;\n\n /**\n * 值变化回调。\n *\n * 受控模式下同样会触发,且此时它是新值唯一的落地路径;因此回调不能只在非受控分支调用。\n */\n onChange?: (value: T) => void;\n}\n\n/**\n * useControllable 的返回值。\n */\nexport interface UseControllableReturn<T> {\n /** 当前值:受控时跟随外部来源,否则是内部状态 */\n value: ComputedRef<T>;\n\n /** 是否处于受控模式 */\n isControlled: ComputedRef<boolean>;\n\n /**\n * 写入新值。\n *\n * 顺序固定为「先落地内部状态,再通知外部」:这样回调里同步读 `value` 得到的就是新值。\n * 受控模式下不写内部(写了就是越权改写调用方的状态),只通知。\n *\n * @param next 目标值。\n */\n set(next: T): void;\n\n /**\n * 只修正内部值,不通知外部。\n *\n * 留给「生命周期兜底修正」这类场景:子项被卸载时要把选中值清掉,但那不是用户操作,\n * 不该冒出一个 change 事件。除这种场合外都应该用 set。\n *\n * @param next 目标值;受控模式下无操作。\n */\n replace(next: T): void;\n}\n\n/**\n * 创建受控 / 非受控状态。\n *\n * @param options 受控来源、默认值与变化回调。\n * @returns 值、受控判定与两种写入方式。\n */\nexport function useControllable<T>(options: UseControllableOptions<T>): UseControllableReturn<T> {\n const controlled = computed(() => toValue(options.value));\n\n const isControlled = computed(() => controlled.value !== undefined);\n\n const internal = shallowRef<T>(options.defaultValue);\n\n const value = computed<T>(() => {\n const current = controlled.value;\n\n return current === undefined ? internal.value : current;\n });\n\n function set(next: T): void {\n if (!isControlled.value) internal.value = next;\n\n options.onChange?.(next);\n }\n\n function replace(next: T): void {\n if (isControlled.value) return;\n\n internal.value = next;\n }\n\n return { value, isControlled, set, replace };\n}\n","/**\n * 运行环境判定。\n *\n * 本库大量 composable 会在 watch 的 immediate 回调里碰 DOM,而 SSR 与非浏览器环境\n * (单元测试的 node 环境)里没有这些全局对象。判据统一放这里,避免每个文件写一份\n * 略有出入的变体(曾经出现过 `typeof window`、`window + document`、\n * `window + HTMLElement` 三种写法),也避免有人用 `typeof document !== 'undefined'`\n * 却去访问 `window` 这类不一致。\n */\n\n/** 是否在浏览器环境中运行。 */\nexport const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';\n\n/**\n * 判断当前环境是否支持某个观察器构造器。\n *\n * jsdom 不实现 ResizeObserver / MutationObserver,直接 new 会抛错而不是静默降级;\n * 各组件的降级路径本来就不同(有的不测量、有的只在事件里测),因此这里只回答\n * 「能不能用」,不替调用方决定怎么办。\n *\n * @param constructor 全局构造器,例如 `globalThis.ResizeObserver`。\n * @returns true 表示可以安全构造。\n */\nexport function isObserverAvailable(constructor: unknown): boolean {\n return typeof constructor === 'function';\n}\n","import { computed, nextTick, onScopeDispose, ref, toValue, watch } from 'vue';\n\nimport { computeAvailableSpace, computeFloatingPosition } from '@agile-plus/primitives/floating';\n\nimport { isBrowser } from '../utils/env';\nimport { useResizeObserver } from '../utils/useResizeObserver';\n\nimport type { CSSProperties } from 'vue';\n\nimport type {\n FloatingArrowPosition,\n FloatingAvailableSpace,\n FloatingPlacement,\n FloatingSnapshot,\n} from '@agile-plus/primitives/floating';\n\nimport type { UseFloatingOptions, UseFloatingReturn } from './types';\n\n/**\n * 浮层定位的 Vue 适配。\n *\n * 职责边界:几何计算全部委托 primitives,本层只做三件事——\n *\n * 1. **Measure**:一次性把锚点、浮层、视口、边界的几何读成快照。读操作集中在一个阶段,\n * 之后不再碰布局,避免读写交错触发强制同步布局。\n * 2. **Calculate**:把快照交给纯函数,得到坐标与实际 placement。\n * 3. **Commit**:把结果写进响应式状态,样式由 computed 派生,写入交给 Vue 的渲染批次。\n *\n * scroll / resize 都是高频事件,统一经 rAF 合并成一次测量;同一帧内重复请求不会排多个任务。\n * 关闭时不挂监听也不测量:不可见的浮层跟随滚动是纯浪费,且此时尺寸为 0,测了也没意义。\n */\nexport function useFloating(options: UseFloatingOptions = {}): UseFloatingReturn {\n const referenceRef = ref<HTMLElement | null>(null);\n const floatingRef = ref<HTMLElement | null>(null);\n\n const x = ref(0);\n const y = ref(0);\n const placement = ref<FloatingPlacement>(toValue(options.placement) ?? 'bottom');\n const arrow = ref<FloatingArrowPosition | null>(null);\n const availableSpace = ref<FloatingAvailableSpace | null>(null);\n\n const isOpen = computed(() => toValue(options.open) ?? true);\n // 默认 absolute:portal 到 body 后浮层落在文档层,窗口滚动由合成器带着它一起移动,\n // 主线程不必逐帧追。fixed 浮层停在视口层,合成器推进滚动的中间帧里它还在旧位置,\n // 实测表现为滚动时浮层抖动、甚至压到触发元素上(间距在 -33…8px 间逐帧跳)。\n const strategy = computed(() => options.strategy ?? 'absolute');\n\n let frame: number | null = null;\n\n const resize = useResizeObserver(requestUpdate);\n\n /** 合并同一帧内的多次更新请求;没有浏览器环境时直接返回。 */\n function requestUpdate(): void {\n if (!isBrowser || frame !== null) return;\n\n frame = window.requestAnimationFrame(() => {\n frame = null;\n\n measure();\n });\n }\n\n /** 一次完整的 Measure → Calculate → Commit。 */\n function measure(): void {\n const reference = referenceRef.value;\n const floating = floatingRef.value;\n\n if (!reference || !floating) return;\n\n // ---- Measure:本阶段之后不再读取任何布局信息 ----\n const referenceRect = reference.getBoundingClientRect();\n const floatingRect = floating.getBoundingClientRect();\n const boundaryRect = toValue(options.boundary)?.getBoundingClientRect();\n const viewport = { width: window.innerWidth, height: window.innerHeight };\n const scrollX = window.scrollX;\n const scrollY = window.scrollY;\n\n const snapshot: FloatingSnapshot = {\n reference: {\n x: referenceRect.x,\n y: referenceRect.y,\n width: referenceRect.width,\n height: referenceRect.height,\n },\n // 浮层自己的 x/y 是上一轮结果,传 0 以免本轮输出依赖历史状态。\n floating: { x: 0, y: 0, width: floatingRect.width, height: floatingRect.height },\n viewport,\n ...(boundaryRect\n ? {\n boundary: {\n x: boundaryRect.x,\n y: boundaryRect.y,\n width: boundaryRect.width,\n height: boundaryRect.height,\n },\n }\n : {}),\n };\n\n // ---- Calculate ----\n const floatingOptions = {\n placement: toValue(options.placement),\n offset: options.offset,\n flip: options.flip,\n shift: options.shift,\n padding: options.padding,\n arrow: options.arrow,\n };\n\n const result = computeFloatingPosition(snapshot, floatingOptions);\n\n // ---- Commit ----\n // 默认 absolute 用页面坐标:浮层 portal 到 body 时 offsetParent 就是文档,见 types 里的前提说明。\n x.value = strategy.value === 'absolute' ? result.x + scrollX : result.x;\n y.value = strategy.value === 'absolute' ? result.y + scrollY : result.y;\n placement.value = result.placement;\n arrow.value = result.arrow;\n // 可用空间与坐标出自同一份快照:消费者限制浮层最大高度时不必再量一次 DOM。\n availableSpace.value = computeAvailableSpace(snapshot, result.placement, floatingOptions);\n }\n\n /**\n * 位移用 transform 而不是 left/top 逐帧改:transform 不触发布局,\n * 滚动跟随这种每帧写入的场景差别明显。left/top 固定为 0 提供定位原点。\n */\n const floatingStyle = computed<CSSProperties>(() => ({\n position: strategy.value,\n left: 0,\n top: 0,\n transform: `translate(${x.value}px, ${y.value}px)`,\n }));\n\n const arrowStyle = computed<CSSProperties>(() => {\n const offset = arrow.value;\n\n if (!offset) return {};\n\n return offset.x !== null\n ? { position: 'absolute', left: `${offset.x}px` }\n : { position: 'absolute', top: `${offset.y}px` };\n });\n\n function attach(): void {\n // capture 才能收到祖先滚动容器派发的 scroll(它不冒泡)。\n window.addEventListener('scroll', requestUpdate, true);\n window.addEventListener('resize', requestUpdate);\n\n resize.observe(referenceRef.value);\n resize.observe(floatingRef.value);\n }\n\n function detach(): void {\n if (!isBrowser) return;\n\n window.removeEventListener('scroll', requestUpdate, true);\n window.removeEventListener('resize', requestUpdate);\n\n resize.disconnect();\n }\n\n watch(\n [isOpen, referenceRef, floatingRef],\n ([open]) => {\n detach();\n\n if (!isBrowser || !open) return;\n\n attach();\n\n // 首帧测量必须在**绘制前**提交:rAF 会晚一帧,让浮层先以原点/旧坐标画一帧再\n // 跳到锚点,表现为「打开后内容自动动一下」。nextTick 回调在本轮渲染补丁之后、\n // 浏览器绘制之前执行,此时浮层已解除 hidden,量到的就是最终尺寸与位置。\n // 滚动 / resize 等后续高频更新仍走 rAF 合并。\n void nextTick(measure);\n },\n { immediate: true }\n );\n\n onScopeDispose(() => {\n detach();\n\n if (frame !== null && isBrowser) {\n window.cancelAnimationFrame(frame);\n frame = null;\n }\n });\n\n return {\n referenceRef,\n floatingRef,\n x: computed(() => x.value),\n y: computed(() => y.value),\n placement: computed(() => placement.value),\n availableSpace: computed(() => availableSpace.value),\n floatingStyle,\n arrowStyle,\n update: requestUpdate,\n };\n}\n","import { onScopeDispose } from 'vue';\n\nimport { isBrowser, isObserverAvailable } from './env';\n\n/**\n * useResizeObserver 的返回值。\n */\nexport interface UseResizeObserverReturn {\n /**\n * 加入观察。重复观察同一元素是安全的(浏览器会去重)。\n *\n * @param element 目标元素,允许 null/undefined 以便直接传响应式 ref 的值。\n */\n observe(element: HTMLElement | null | undefined): void;\n\n /**\n * 停止观察单个元素;元素被替换时用它摘掉旧目标。\n *\n * @param element 目标元素。\n */\n unobserve(element: HTMLElement): void;\n\n /** 断开全部观察。作用域销毁时会自动调用,手动调用只用于提前释放。 */\n disconnect(): void;\n}\n\n/**\n * 共享的尺寸观察器。\n *\n * ScrollArea(视口 + 内容首子元素)、Slider(多个 thumb)、Switch(按钮本体)都要\n * 监听元素尺寸变化,但**测什么、测完做什么各不相同**,所以这里只统一三件真正相同的\n * 事:环境守卫(jsdom / SSR 没有 ResizeObserver)、懒创建、随作用域释放。把\n * `useElementSize` 这种「测量即结束」的形状强套给前两者,只会逼它们绕开钩子。\n *\n * @param onResize 任一被观察元素尺寸变化时的回调,节流/合并由调用方自己决定。\n * @returns 观察与释放入口。\n */\nexport function useResizeObserver(onResize: () => void): UseResizeObserverReturn {\n let observer: ResizeObserver | null = null;\n\n function observe(element: HTMLElement | null | undefined): void {\n if (!element || !isBrowser || !isObserverAvailable(globalThis.ResizeObserver)) return;\n\n observer ??= new ResizeObserver(() => onResize());\n observer.observe(element);\n }\n\n function unobserve(element: HTMLElement): void {\n observer?.unobserve(element);\n }\n\n function disconnect(): void {\n observer?.disconnect();\n observer = null;\n }\n\n onScopeDispose(disconnect);\n\n return { observe, unobserve, disconnect };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,cAAgE;;;ACAhE,iBAA8C;AAqEvC,SAAS,gBAAmB,SAA8D;AAC/F,QAAM,iBAAa,qBAAS,UAAM,oBAAQ,QAAQ,KAAK,CAAC;AAExD,QAAM,mBAAe,qBAAS,MAAM,WAAW,UAAU,MAAS;AAElE,QAAM,eAAW,uBAAc,QAAQ,YAAY;AAEnD,QAAM,YAAQ,qBAAY,MAAM;AAC9B,UAAM,UAAU,WAAW;AAE3B,WAAO,YAAY,SAAY,SAAS,QAAQ;AAAA,EAClD,CAAC;AAED,WAAS,IAAI,MAAe;AAC1B,QAAI,CAAC,aAAa,MAAO,UAAS,QAAQ;AAE1C,YAAQ,WAAW,IAAI;AAAA,EACzB;AAEA,WAAS,QAAQ,MAAe;AAC9B,QAAI,aAAa,MAAO;AAExB,aAAS,QAAQ;AAAA,EACnB;AAEA,SAAO,EAAE,OAAO,cAAc,KAAK,QAAQ;AAC7C;;;ACpFO,IAAM,YAAY,OAAO,WAAW,eAAe,OAAO,aAAa;AAYvE,SAAS,oBAAoB,aAA+B;AACjE,SAAO,OAAO,gBAAgB;AAChC;;;ACzBA,IAAAC,cAAwE;AAExE,sBAA+D;;;ACF/D,IAAAC,cAA+B;AAqCxB,SAAS,kBAAkB,UAA+C;AAC/E,MAAI,WAAkC;AAEtC,WAAS,QAAQ,SAA+C;AAC9D,QAAI,CAAC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AAAA,MACV,cAAc,OAAO,QAAQ,SAAS;AAAA,IACxC;AAAA,EACF;AAEA,WAAS,gBAAyC;AAChD,WAAO,EAAE,MAAM,SAAS;AAAA,EAC1B;AAEA,WAAS,kBAAkB,MAAqB;AAC9C,aAAS,aAAa,QAAQ,gBAAgB,cAAc,OAAO;AAAA,EACrE;AAEA,WAAS,kBAAkB,MAAqB;AAC9C,aAAS,YAAY,QAAQ,gBAAgB,cAAc,OAAO;AAAA,EACpE;AAEA,WAAS,0BAA0B,OAA2B;AAC5D,UAAM,SAAS,MAAM;AAErB,QAAI,EAAE,kBAAkB,MAAO;AAE/B,UAAM,UAAU,SAAS,aAAa;AACtC,UAAM,UAAU,SAAS,YAAY;AAErC,QAAI,SAAS,SAAS,MAAM,KAAK,SAAS,SAAS,MAAM,EAAG;AAE5D,UAAM;AAAA,EACR;AAEA;AAAA,IACE;AAAA,IACA,CAACC,UAAS;AACR,UAAI,CAAC,UAAW;AAEhB,eAAS,oBAAoB,eAAe,2BAA2B,IAAI;AAE3E,UAAIA,OAAM;AACR,iBAAS,iBAAiB,eAAe,2BAA2B,IAAI;AAKxE,iBAAK,sBAAS,MAAM;AAClB,mBAAS,YAAY,OAAO,MAAM,EAAE,eAAe,KAAK,CAAC;AAAA,QAC3D,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,EAAE,WAAW,KAAK;AAAA,EACpB;AAEA,kCAAe,MAAM;AACnB,QAAI,UAAW,UAAS,oBAAoB,eAAe,2BAA2B,IAAI;AAAA,EAC5F,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["import_vue","import_vue","import_vue","open"]}
@@ -0,0 +1,71 @@
1
+ import { MaybeRefOrGetter, ComputedRef } from 'vue';
2
+ import { FloatingPlacement, FloatingOffset, FloatingArrowOptions } from '@agile-plus/primitives/floating';
3
+ import { F as FloatingStrategy, a as UseFloatingReturn } from '../types-zpeY0yvD.cjs';
4
+
5
+ /** usePopover 的配置。 */
6
+ interface UsePopoverOptions {
7
+ /** 受控开合;undefined 表示非受控 */
8
+ open?: MaybeRefOrGetter<boolean | undefined>;
9
+ /** 非受控初值,默认 false */
10
+ defaultOpen?: boolean;
11
+ /** 开合变化回调 */
12
+ onOpenChange?: (open: boolean) => void;
13
+ /** 按 Escape 是否关闭,默认 true */
14
+ closeOnEscape?: boolean;
15
+ /** 期望位置,默认 'bottom' */
16
+ placement?: FloatingPlacement;
17
+ /** 与触发元素间距,默认 8 */
18
+ offset?: number | FloatingOffset;
19
+ /** 空间不足时翻转,默认 true */
20
+ flip?: boolean;
21
+ /** 沿交叉轴钳制,默认 true */
22
+ shift?: boolean;
23
+ /** 与边界最小留白,默认 8 */
24
+ padding?: number;
25
+ /** 定位策略,默认 'fixed' */
26
+ strategy?: FloatingStrategy;
27
+ /** 需要箭头时给出尺寸;缺省 { size: 8 },不渲染 Arrow 部件时无副作用 */
28
+ arrow?: FloatingArrowOptions;
29
+ }
30
+ /** usePopover 的返回值。 */
31
+ interface UsePopoverReturn {
32
+ /** 是否打开 */
33
+ isOpen: ComputedRef<boolean>;
34
+ /** 打开 */
35
+ open(): void;
36
+ /** 关闭并把焦点交还触发元素(若焦点曾在浮层内) */
37
+ close(): void;
38
+ /** 切换开合 */
39
+ toggle(): void;
40
+ /** 触发元素 id */
41
+ triggerId: string;
42
+ /** 浮层 id */
43
+ contentId: string;
44
+ /** 定位能力 */
45
+ floating: UseFloatingReturn;
46
+ /** 触发元素属性 */
47
+ getTriggerProps(): Record<string, unknown>;
48
+ /** 浮层属性 */
49
+ getContentProps(): Record<string, unknown>;
50
+ /** 关闭按钮属性 */
51
+ getCloseProps(): Record<string, unknown>;
52
+ /** 绑定触发元素 */
53
+ setTriggerElement(node: unknown): void;
54
+ /** 绑定浮层元素 */
55
+ setContentElement(node: unknown): void;
56
+ /** 浮层键盘处理器(Escape 关闭) */
57
+ onContentKeydown(event: KeyboardEvent): void;
58
+ }
59
+
60
+ /**
61
+ * Popover 的 Vue 适配。
62
+ *
63
+ * 非模态浮层:不锁滚动、不做焦点陷阱;打开时由 UI 层把焦点移进浮层,关闭时若焦点
64
+ * 曾在浮层内则交还触发元素。外部指针按下与 Escape 关闭。
65
+ *
66
+ * 内容**懒渲染**:UI 层用 usePresence 的 v-if 驱动,关闭即卸载,打开才挂载;本层只
67
+ * 持有开合状态与定位,不持有内容 DOM。
68
+ */
69
+ declare function usePopover(options?: UsePopoverOptions): UsePopoverReturn;
70
+
71
+ export { type UsePopoverOptions, type UsePopoverReturn, usePopover };
@@ -0,0 +1,71 @@
1
+ import { MaybeRefOrGetter, ComputedRef } from 'vue';
2
+ import { FloatingPlacement, FloatingOffset, FloatingArrowOptions } from '@agile-plus/primitives/floating';
3
+ import { F as FloatingStrategy, a as UseFloatingReturn } from '../types-zpeY0yvD.js';
4
+
5
+ /** usePopover 的配置。 */
6
+ interface UsePopoverOptions {
7
+ /** 受控开合;undefined 表示非受控 */
8
+ open?: MaybeRefOrGetter<boolean | undefined>;
9
+ /** 非受控初值,默认 false */
10
+ defaultOpen?: boolean;
11
+ /** 开合变化回调 */
12
+ onOpenChange?: (open: boolean) => void;
13
+ /** 按 Escape 是否关闭,默认 true */
14
+ closeOnEscape?: boolean;
15
+ /** 期望位置,默认 'bottom' */
16
+ placement?: FloatingPlacement;
17
+ /** 与触发元素间距,默认 8 */
18
+ offset?: number | FloatingOffset;
19
+ /** 空间不足时翻转,默认 true */
20
+ flip?: boolean;
21
+ /** 沿交叉轴钳制,默认 true */
22
+ shift?: boolean;
23
+ /** 与边界最小留白,默认 8 */
24
+ padding?: number;
25
+ /** 定位策略,默认 'fixed' */
26
+ strategy?: FloatingStrategy;
27
+ /** 需要箭头时给出尺寸;缺省 { size: 8 },不渲染 Arrow 部件时无副作用 */
28
+ arrow?: FloatingArrowOptions;
29
+ }
30
+ /** usePopover 的返回值。 */
31
+ interface UsePopoverReturn {
32
+ /** 是否打开 */
33
+ isOpen: ComputedRef<boolean>;
34
+ /** 打开 */
35
+ open(): void;
36
+ /** 关闭并把焦点交还触发元素(若焦点曾在浮层内) */
37
+ close(): void;
38
+ /** 切换开合 */
39
+ toggle(): void;
40
+ /** 触发元素 id */
41
+ triggerId: string;
42
+ /** 浮层 id */
43
+ contentId: string;
44
+ /** 定位能力 */
45
+ floating: UseFloatingReturn;
46
+ /** 触发元素属性 */
47
+ getTriggerProps(): Record<string, unknown>;
48
+ /** 浮层属性 */
49
+ getContentProps(): Record<string, unknown>;
50
+ /** 关闭按钮属性 */
51
+ getCloseProps(): Record<string, unknown>;
52
+ /** 绑定触发元素 */
53
+ setTriggerElement(node: unknown): void;
54
+ /** 绑定浮层元素 */
55
+ setContentElement(node: unknown): void;
56
+ /** 浮层键盘处理器(Escape 关闭) */
57
+ onContentKeydown(event: KeyboardEvent): void;
58
+ }
59
+
60
+ /**
61
+ * Popover 的 Vue 适配。
62
+ *
63
+ * 非模态浮层:不锁滚动、不做焦点陷阱;打开时由 UI 层把焦点移进浮层,关闭时若焦点
64
+ * 曾在浮层内则交还触发元素。外部指针按下与 Escape 关闭。
65
+ *
66
+ * 内容**懒渲染**:UI 层用 usePresence 的 v-if 驱动,关闭即卸载,打开才挂载;本层只
67
+ * 持有开合状态与定位,不持有内容 DOM。
68
+ */
69
+ declare function usePopover(options?: UsePopoverOptions): UsePopoverReturn;
70
+
71
+ export { type UsePopoverOptions, type UsePopoverReturn, usePopover };