@marianmeres/stuic 2.28.0 → 2.30.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;
@@ -378,6 +392,28 @@ export function popover(anchorEl, fn) {
378
392
  }
379
393
  // Render content
380
394
  renderContent();
395
+ // Add close button for fallback mode (after content so it's not cleared)
396
+ if (!useAnchorPositioning && popoverEl) {
397
+ const closeBtn = document.createElement("button");
398
+ closeBtn.setAttribute("type", "button");
399
+ closeBtn.setAttribute("aria-label", "Close");
400
+ closeBtn.innerHTML = `<svg fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor" style="width:1.25rem;height:1.25rem"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12" /></svg>`;
401
+ closeBtn.style.cssText = `
402
+ position: absolute;
403
+ top: 0;
404
+ right: 0;
405
+ background: black;
406
+ color: white;
407
+ border: none;
408
+ border-bottom-left-radius: 0.5rem;
409
+ cursor: pointer;
410
+ opacity: 0.8;
411
+ padding: 0.33rem;
412
+ line-height: 1;
413
+ `;
414
+ closeBtn.addEventListener("click", hide);
415
+ popoverEl.appendChild(closeBtn);
416
+ }
381
417
  // Transition in
382
418
  popoverEl.classList.add("pop-block");
383
419
  requestAnimationFrame(() => {
@@ -409,6 +445,9 @@ export function popover(anchorEl, fn) {
409
445
  if (!isVisible)
410
446
  return;
411
447
  isVisible = false;
448
+ if (currentOptions.id) {
449
+ popoverOpenStates[currentOptions.id] = false;
450
+ }
412
451
  // Unregister from open popovers
413
452
  openPopovers.delete(hide);
414
453
  anchorEl.setAttribute("aria-expanded", "false");
@@ -547,6 +586,7 @@ export function popover(anchorEl, fn) {
547
586
  // Unregister from popover registry
548
587
  if (currentOptions.id) {
549
588
  popoverRegistry.delete(currentOptions.id);
589
+ delete popoverOpenStates[currentOptions.id];
550
590
  }
551
591
  document.removeEventListener("keydown", onEscape);
552
592
  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.30.0",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",