@brightlocal/ui-components 2.18.0 → 2.20.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 (67) hide show
  1. package/README.md +1 -1
  2. package/component-meta.json +11 -2
  3. package/dist/alert-dialog.cjs +1 -1
  4. package/dist/alert-dialog.d.ts.map +1 -1
  5. package/dist/alert-dialog.js +34 -33
  6. package/dist/blocks/sidebar.cjs +1 -1
  7. package/dist/blocks/sidebar.d.ts +20 -0
  8. package/dist/blocks/sidebar.d.ts.map +1 -1
  9. package/dist/blocks/sidebar.js +423 -390
  10. package/dist/browser-entry.d.ts +2 -0
  11. package/dist/browser-entry.d.ts.map +1 -1
  12. package/dist/context-menu.cjs +1 -1
  13. package/dist/context-menu.d.ts.map +1 -1
  14. package/dist/context-menu.js +47 -46
  15. package/dist/dialog.cjs +1 -1
  16. package/dist/dialog.d.ts.map +1 -1
  17. package/dist/dialog.js +35 -34
  18. package/dist/dropdown-menu.cjs +1 -1
  19. package/dist/dropdown-menu.d.ts.map +1 -1
  20. package/dist/dropdown-menu.js +48 -47
  21. package/dist/global-layout.cjs +1 -1
  22. package/dist/global-layout.d.ts.map +1 -1
  23. package/dist/global-layout.js +44 -42
  24. package/dist/hooks/use-overlay-pointer-lock.cjs +1 -0
  25. package/dist/hooks/use-overlay-pointer-lock.d.ts +20 -0
  26. package/dist/hooks/use-overlay-pointer-lock.d.ts.map +1 -0
  27. package/dist/hooks/use-overlay-pointer-lock.js +39 -0
  28. package/dist/index.cjs +1 -1
  29. package/dist/index.d.ts +1 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +88 -86
  32. package/dist/logo.cjs +1 -1
  33. package/dist/logo.d.ts.map +1 -1
  34. package/dist/logo.js +44 -37
  35. package/dist/popover.cjs +1 -1
  36. package/dist/popover.d.ts.map +1 -1
  37. package/dist/popover.js +21 -20
  38. package/dist/select.cjs +1 -1
  39. package/dist/select.d.ts.map +1 -1
  40. package/dist/select.js +25 -23
  41. package/dist/separator.cjs +1 -1
  42. package/dist/separator.d.ts +14 -0
  43. package/dist/separator.d.ts.map +1 -1
  44. package/dist/separator.js +90 -44
  45. package/dist/sheet.cjs +1 -1
  46. package/dist/sheet.d.ts.map +1 -1
  47. package/dist/sheet.js +29 -28
  48. package/dist/stepper.cjs +1 -1
  49. package/dist/stepper.d.ts +15 -13
  50. package/dist/stepper.d.ts.map +1 -1
  51. package/dist/stepper.js +84 -85
  52. package/package.json +3 -3
  53. package/src/blocks/sidebar.tsx +81 -14
  54. package/src/browser-entry.ts +10 -0
  55. package/src/components/alert-dialog.tsx +20 -14
  56. package/src/components/context-menu.tsx +19 -13
  57. package/src/components/dialog.tsx +4 -0
  58. package/src/components/dropdown-menu.tsx +4 -0
  59. package/src/components/global-layout.tsx +3 -1
  60. package/src/components/logo.tsx +19 -25
  61. package/src/components/popover.tsx +22 -16
  62. package/src/components/select.tsx +4 -0
  63. package/src/components/separator.tsx +91 -23
  64. package/src/components/sheet.tsx +4 -0
  65. package/src/components/stepper.tsx +93 -80
  66. package/src/hooks/use-overlay-pointer-lock.ts +128 -0
  67. package/src/index.ts +1 -0
@@ -0,0 +1,128 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+
5
+ /**
6
+ * Elements that indicate an overlay is genuinely open and may therefore
7
+ * legitimately hold the `document.body` pointer-events lock.
8
+ *
9
+ * Keyed on `data-state="open"` so a closing/orphaned overlay remnant — the very
10
+ * thing DS-634 leaves behind ("the menu is still tearing down") — is treated as
11
+ * NOT open and cannot block the release. The DS `data-slot` entries give precise
12
+ * coverage (including Popover/Select, whose content carries no ARIA role), and
13
+ * the generic `role` entries are a safety net so the guard also refuses to clear
14
+ * a lock owned by a non-DS Radix overlay, or by a DS overlay whose `data-slot`
15
+ * was overridden via props (e.g. Combobox's `combobox-popover`). It never clears
16
+ * a lock it cannot see is open.
17
+ */
18
+ const OPEN_OVERLAY_SELECTOR = [
19
+ '[data-slot="dialog-content"][data-state="open"]',
20
+ '[data-slot="alert-dialog-content"][data-state="open"]',
21
+ '[data-slot="sheet-content"][data-state="open"]',
22
+ '[data-slot="dropdown-menu-content"][data-state="open"]',
23
+ '[data-slot="dropdown-menu-sub-content"][data-state="open"]',
24
+ '[data-slot="context-menu-content"][data-state="open"]',
25
+ '[data-slot="context-menu-sub-content"][data-state="open"]',
26
+ '[data-slot="popover-content"][data-state="open"]',
27
+ '[data-slot="select-content"][data-state="open"]',
28
+ // Generic fallbacks: any open Radix overlay (or overridden DS one) by role.
29
+ '[role="dialog"][data-state="open"]',
30
+ '[role="alertdialog"][data-state="open"]',
31
+ '[role="menu"][data-state="open"]',
32
+ '[role="listbox"][data-state="open"]',
33
+ ].join(",");
34
+
35
+ /** Whether the one-time global watchers (observer + listeners) are installed. */
36
+ let watchersInstalled = false;
37
+
38
+ /**
39
+ * Clears a residual `pointer-events: none` inline lock from `document.body`,
40
+ * but only when no overlay is open.
41
+ *
42
+ * Radix's `react-dismissable-layer` stores the body's "original" pointer-events
43
+ * in a single module-level variable shared across every layer. When one overlay
44
+ * opens another (e.g. a `DropdownMenu` item opens a `Dialog`) that variable can
45
+ * capture `none`, so a later cleanup restores the body to `none` and the whole
46
+ * page becomes unclickable until reload (DS-634).
47
+ *
48
+ * The release is conservative: it acts only when the body is actually stuck at
49
+ * `none` AND nothing that could own the lock is on screen, so it never fights a
50
+ * genuinely open modal (DS or otherwise). Erring toward leaving a lock in place
51
+ * is safe; clearing one that is still owned is not.
52
+ */
53
+ function releaseBodyPointerLockIfIdle() {
54
+ if (typeof document === "undefined") return;
55
+ if (document.body.style.pointerEvents !== "none") return;
56
+ if (document.querySelector(OPEN_OVERLAY_SELECTOR) !== null) return;
57
+ document.body.style.pointerEvents = "";
58
+ }
59
+
60
+ /**
61
+ * Defer a release so Radix's own (buggy) cleanup runs first, then we correct it.
62
+ * Falls back to a timeout where `requestAnimationFrame` is unavailable (SSR,
63
+ * some test runners) so the release still fires.
64
+ */
65
+ function scheduleRelease() {
66
+ if (typeof requestAnimationFrame === "function") {
67
+ requestAnimationFrame(releaseBodyPointerLockIfIdle);
68
+ } else if (typeof setTimeout === "function") {
69
+ setTimeout(releaseBodyPointerLockIfIdle, 0);
70
+ }
71
+ }
72
+
73
+ function handleReturnToPage() {
74
+ // `window.open` / new-tab from a menu item can leave the lock stuck; re-check
75
+ // when the user comes back to the page (bfcache restore included).
76
+ if (typeof document === "undefined") return;
77
+ if (document.visibilityState === "visible") releaseBodyPointerLockIfIdle();
78
+ }
79
+
80
+ function installGlobalWatchers() {
81
+ if (watchersInstalled || typeof document === "undefined") return;
82
+ watchersInstalled = true;
83
+
84
+ document.addEventListener("visibilitychange", handleReturnToPage);
85
+ // `pageshow` fires on bfcache restore where `visibilitychange` may not.
86
+ window.addEventListener("pageshow", handleReturnToPage);
87
+
88
+ // The observer and the per-unmount rAF (below) are complementary, not
89
+ // redundant: the rAF handles the common case where the last overlay unmounts
90
+ // leaving the body stuck at `none` with no further style write, while the
91
+ // observer catches Radix re-writing `none` in a *later* deferred cleanup that
92
+ // the single rAF would miss. Because the release is gated on
93
+ // OPEN_OVERLAY_SELECTOR, the observer only ever undoes an orphaned lock and
94
+ // never one an open overlay owns. Setting the value back to "" is a no-op for
95
+ // the guard (it early-returns unless the value is "none"), so no feedback loop.
96
+ if (typeof MutationObserver !== "undefined") {
97
+ const observer = new MutationObserver(releaseBodyPointerLockIfIdle);
98
+ observer.observe(document.body, {
99
+ attributes: true,
100
+ attributeFilter: ["style"],
101
+ });
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Safety net for a long-standing Radix `react-dismissable-layer` bug where
107
+ * nested overlays can leave `document.body { pointer-events: none }` stuck,
108
+ * freezing the entire page (see DS-634).
109
+ *
110
+ * Each DS overlay whose content can lock outside pointer events calls this hook
111
+ * while it is open. It installs one set of global watchers (a `MutationObserver`
112
+ * on the body's inline style plus tab-return listeners) and, on unmount, clears
113
+ * a residual body lock — but only once no overlay (DS or otherwise) remains on
114
+ * screen, so legitimate modal behaviour (scroll-lock, focus containment,
115
+ * outside-click/Escape) is untouched.
116
+ *
117
+ * Automatically wired into the DS overlay components, so consumers get the fix
118
+ * with no code changes. It is also safe to call from a custom overlay that
119
+ * exposes a standard `role` (dialog/alertdialog/menu/listbox) with
120
+ * `data-state="open"` while open — the guard will not clear a lock it can see is
121
+ * still owned.
122
+ */
123
+ export function useOverlayPointerLock(): void {
124
+ React.useEffect(() => {
125
+ installGlobalWatchers();
126
+ return scheduleRelease;
127
+ }, []);
128
+ }
package/src/index.ts CHANGED
@@ -74,6 +74,7 @@ export * from "./blocks/sidebar";
74
74
  export * from "./hooks/use-debounce";
75
75
  export * from "./hooks/use-breakpoint";
76
76
  export * from "./hooks/use-mobile";
77
+ export * from "./hooks/use-overlay-pointer-lock";
77
78
  export * from "./hooks/use-prefers-reduced-motion";
78
79
 
79
80
  // Utils