@marianmeres/stuic 2.28.0 → 2.29.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.
@@ -26,6 +26,13 @@ export declare function closePopover(id: string): void;
26
26
  * @param id - The popover ID to toggle
27
27
  */
28
28
  export declare function togglePopover(id: string): void;
29
+ /**
30
+ * Check if a popover is currently open by its registered ID.
31
+ *
32
+ * @param id - The popover ID to check
33
+ * @returns true if the popover is open, false otherwise
34
+ */
35
+ export declare function isPopoverOpen(id: string): boolean;
29
36
  /**
30
37
  * Checks if the browser supports CSS Anchor Positioning for popovers.
31
38
  *
@@ -6,6 +6,8 @@ import PopoverContent from "./PopoverContent.svelte";
6
6
  import "./index.css";
7
7
  // Registry of open popover hide functions for closeOthers feature
8
8
  const openPopovers = new Set();
9
+ // Reactive state tracking which popovers are open by ID
10
+ const popoverOpenStates = $state({});
9
11
  // Registry of popovers by ID for programmatic control
10
12
  const popoverRegistry = new Map();
11
13
  // Track if an open was just requested (to prevent same-click outside close)
@@ -54,6 +56,15 @@ export function closePopover(id) {
54
56
  export function togglePopover(id) {
55
57
  popoverRegistry.get(id)?.toggle();
56
58
  }
59
+ /**
60
+ * Check if a popover is currently open by its registered ID.
61
+ *
62
+ * @param id - The popover ID to check
63
+ * @returns true if the popover is open, false otherwise
64
+ */
65
+ export function isPopoverOpen(id) {
66
+ return popoverOpenStates[id] ?? false;
67
+ }
57
68
  const SHOW_DELAY = 100;
58
69
  const HIDE_DELAY = 200;
59
70
  const TRANSITION = 200;
@@ -310,6 +321,9 @@ export function popover(anchorEl, fn) {
310
321
  // Register this popover
311
322
  openPopovers.add(hide);
312
323
  isVisible = true;
324
+ if (currentOptions.id) {
325
+ popoverOpenStates[currentOptions.id] = true;
326
+ }
313
327
  anchorEl.setAttribute("aria-expanded", "true");
314
328
  const offsetValue = currentOptions.offset || "0.25rem";
315
329
  const useAnchorPositioning = isSupported && !currentOptions.forceFallback;
@@ -409,6 +423,9 @@ export function popover(anchorEl, fn) {
409
423
  if (!isVisible)
410
424
  return;
411
425
  isVisible = false;
426
+ if (currentOptions.id) {
427
+ popoverOpenStates[currentOptions.id] = false;
428
+ }
412
429
  // Unregister from open popovers
413
430
  openPopovers.delete(hide);
414
431
  anchorEl.setAttribute("aria-expanded", "false");
@@ -547,6 +564,7 @@ export function popover(anchorEl, fn) {
547
564
  // Unregister from popover registry
548
565
  if (currentOptions.id) {
549
566
  popoverRegistry.delete(currentOptions.id);
567
+ delete popoverOpenStates[currentOptions.id];
550
568
  }
551
569
  document.removeEventListener("keydown", onEscape);
552
570
  document.removeEventListener("click", onClickOutside);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/stuic",
3
- "version": "2.28.0",
3
+ "version": "2.29.0",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",