react-bounded-overlay-manager 1.0.0-beta.1

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 (84) hide show
  1. package/README.md +30 -0
  2. package/dist/assets/Overlay.css +1 -0
  3. package/dist/assets/OverlaysContainer.css +1 -0
  4. package/dist/events-B7I8KoZ9.js +228 -0
  5. package/dist/index-7ofMxoL9.js +8811 -0
  6. package/dist/index.module-WXM1Xk0w.js +60 -0
  7. package/dist/main.d.ts +7 -0
  8. package/dist/main.js +12 -0
  9. package/dist/react.esm-GKFzux-6.js +12736 -0
  10. package/dist/src/api/BoundedOverlayManagerApi.d.ts +14 -0
  11. package/dist/src/api/BoundedOverlayManagerApi.js +24 -0
  12. package/dist/src/components/BoundedOverlayManager.d.ts +7 -0
  13. package/dist/src/components/BoundedOverlayManager.js +17 -0
  14. package/dist/src/components/BoundedOverlayManagerContent.d.ts +15 -0
  15. package/dist/src/components/BoundedOverlayManagerContent.js +46 -0
  16. package/dist/src/components/Overlay.d.ts +26 -0
  17. package/dist/src/components/Overlay.js +43 -0
  18. package/dist/src/components/OverlaysContainer.d.ts +11 -0
  19. package/dist/src/components/OverlaysContainer.js +12 -0
  20. package/dist/src/components/test/BoundedOverlayManager.test.d.ts +0 -0
  21. package/dist/src/components/test/BoundedOverlayManager.test.js +37 -0
  22. package/dist/src/components/test/BoundedOverlayManagerContent.test.d.ts +0 -0
  23. package/dist/src/components/test/BoundedOverlayManagerContent.test.js +92 -0
  24. package/dist/src/components/test/Overlay.test.d.ts +0 -0
  25. package/dist/src/components/test/Overlay.test.js +245 -0
  26. package/dist/src/components/test/OverlaysContainer.test.d.ts +0 -0
  27. package/dist/src/components/test/OverlaysContainer.test.js +36 -0
  28. package/dist/src/config.d.ts +6 -0
  29. package/dist/src/config.js +9 -0
  30. package/dist/src/context/OverlayManagerContext.d.ts +13 -0
  31. package/dist/src/context/OverlayManagerContext.js +23 -0
  32. package/dist/src/context/test/OverlayManagerContext.test.d.ts +1 -0
  33. package/dist/src/context/test/OverlayManagerContext.test.js +31 -0
  34. package/dist/src/enum/PredefinedPosition.d.ts +12 -0
  35. package/dist/src/enum/PredefinedPosition.js +4 -0
  36. package/dist/src/hooks/test/useApiUpdateHandler.test.d.ts +1 -0
  37. package/dist/src/hooks/test/useApiUpdateHandler.test.js +28 -0
  38. package/dist/src/hooks/test/useForwardBoundingComponentEvents.test.d.ts +1 -0
  39. package/dist/src/hooks/test/useForwardBoundingComponentEvents.test.js +62 -0
  40. package/dist/src/hooks/test/useForwardOverlayEvents.test.d.ts +1 -0
  41. package/dist/src/hooks/test/useForwardOverlayEvents.test.js +43 -0
  42. package/dist/src/hooks/test/useFullscreenChange.test.d.ts +1 -0
  43. package/dist/src/hooks/test/useFullscreenChange.test.js +33 -0
  44. package/dist/src/hooks/test/useOverlayManagerEvents.test.d.ts +1 -0
  45. package/dist/src/hooks/test/useOverlayManagerEvents.test.js +87 -0
  46. package/dist/src/hooks/test/useResizeObserver.test.d.ts +1 -0
  47. package/dist/src/hooks/test/useResizeObserver.test.js +47 -0
  48. package/dist/src/hooks/test/useScrollOnDocument.test.d.ts +1 -0
  49. package/dist/src/hooks/test/useScrollOnDocument.test.js +38 -0
  50. package/dist/src/hooks/test/useTimedEventManager.test.d.ts +1 -0
  51. package/dist/src/hooks/test/useTimedEventManager.test.js +41 -0
  52. package/dist/src/hooks/test/useWindowResize.test.d.ts +1 -0
  53. package/dist/src/hooks/test/useWindowResize.test.js +38 -0
  54. package/dist/src/hooks/test/util.d.ts +7 -0
  55. package/dist/src/hooks/test/util.js +20 -0
  56. package/dist/src/hooks/useApiUpdateHandler.d.ts +6 -0
  57. package/dist/src/hooks/useApiUpdateHandler.js +10 -0
  58. package/dist/src/hooks/useForwardBoundingComponentEvents.d.ts +2 -0
  59. package/dist/src/hooks/useForwardBoundingComponentEvents.js +20 -0
  60. package/dist/src/hooks/useForwardOverlayEvents.d.ts +6 -0
  61. package/dist/src/hooks/useForwardOverlayEvents.js +21 -0
  62. package/dist/src/hooks/useFullscreenChange.d.ts +5 -0
  63. package/dist/src/hooks/useFullscreenChange.js +16 -0
  64. package/dist/src/hooks/useOverlayManagerEvents.d.ts +8 -0
  65. package/dist/src/hooks/useOverlayManagerEvents.js +34 -0
  66. package/dist/src/hooks/useResizeObserver.d.ts +6 -0
  67. package/dist/src/hooks/useResizeObserver.js +19 -0
  68. package/dist/src/hooks/useScrollOnDocument.d.ts +5 -0
  69. package/dist/src/hooks/useScrollOnDocument.js +11 -0
  70. package/dist/src/hooks/useTimedEventManager.d.ts +6 -0
  71. package/dist/src/hooks/useTimedEventManager.js +15 -0
  72. package/dist/src/hooks/useWindowResize.d.ts +5 -0
  73. package/dist/src/hooks/useWindowResize.js +11 -0
  74. package/dist/src/timer/TimedEventManager.d.ts +16 -0
  75. package/dist/src/timer/TimedEventManager.js +25 -0
  76. package/dist/src/timer/test/TimedEventManager.test.d.ts +1 -0
  77. package/dist/src/timer/test/TimedEventManager.test.js +26 -0
  78. package/dist/src/types/OffsetProps.d.ts +37 -0
  79. package/dist/src/types/OffsetProps.js +1 -0
  80. package/dist/src/util/bbox.d.ts +7 -0
  81. package/dist/src/util/bbox.js +20 -0
  82. package/dist/vite-env.d.js +1 -0
  83. package/dist/vite.svg +1 -0
  84. package/package.json +70 -0
@@ -0,0 +1,14 @@
1
+ import TimedEventManager from "../timer/TimedEventManager";
2
+ export type BoundedOverlayManagerApiOptions = {
3
+ timedEventManager: TimedEventManager | null;
4
+ updateOverlaysContainerBoundingBox: () => void;
5
+ };
6
+ declare class BoundedOverlayManagerApi {
7
+ private timedEventManager;
8
+ private _updateOverlaysContainerBoundingBox;
9
+ constructor({ timedEventManager, updateOverlaysContainerBoundingBox }: BoundedOverlayManagerApiOptions);
10
+ renderOverlays(): void;
11
+ clearOverlays(): void;
12
+ updateOverlaysContainerBoundingBox(): void;
13
+ }
14
+ export default BoundedOverlayManagerApi;
@@ -0,0 +1,24 @@
1
+ var r = Object.defineProperty;
2
+ var i = (t, e, a) => e in t ? r(t, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : t[e] = a;
3
+ var n = (t, e, a) => (i(t, typeof e != "symbol" ? e + "" : e, a), a);
4
+ class s {
5
+ constructor({ timedEventManager: e, updateOverlaysContainerBoundingBox: a }) {
6
+ n(this, "timedEventManager");
7
+ n(this, "_updateOverlaysContainerBoundingBox");
8
+ this.timedEventManager = e, this._updateOverlaysContainerBoundingBox = a;
9
+ }
10
+ renderOverlays() {
11
+ var e;
12
+ (e = this.timedEventManager) == null || e.requestStart();
13
+ }
14
+ clearOverlays() {
15
+ var e;
16
+ (e = this.timedEventManager) == null || e.requestStop();
17
+ }
18
+ updateOverlaysContainerBoundingBox() {
19
+ this._updateOverlaysContainerBoundingBox();
20
+ }
21
+ }
22
+ export {
23
+ s as default
24
+ };
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import BoundedOverlayManagerContent from './BoundedOverlayManagerContent';
3
+ type Props = React.ComponentProps<typeof BoundedOverlayManagerContent> & {
4
+ boundingComponentRef: React.RefObject<HTMLElement>;
5
+ };
6
+ declare const BoundedOverlayManager: React.FC<Props>;
7
+ export default BoundedOverlayManager;
@@ -0,0 +1,17 @@
1
+ import { jsx as t } from "react/jsx-runtime";
2
+ import { useState as m, useCallback as s } from "react";
3
+ import u from "react-dom";
4
+ import d from "../hooks/useFullscreenChange.js";
5
+ import { OverlayManagerContextProvider as i } from "../context/OverlayManagerContext.js";
6
+ import f from "./BoundedOverlayManagerContent.js";
7
+ const r = () => document.fullscreenElement || document.body, M = ({ boundingComponentRef: o, ...n }) => {
8
+ const [a, e] = m(r), l = s(() => {
9
+ e(r());
10
+ }, [e]);
11
+ d({ handleFullscreenChange: l });
12
+ const c = /* @__PURE__ */ t(i, { boundingComponentRef: o, children: /* @__PURE__ */ t(f, { ...n }) });
13
+ return u.createPortal(c, a);
14
+ };
15
+ export {
16
+ M as default
17
+ };
@@ -0,0 +1,15 @@
1
+ import { ReactElement } from "react";
2
+ import Overlay from "./Overlay";
3
+ import BoundedOverlayManagerApi from "../api/BoundedOverlayManagerApi";
4
+ type Props = {
5
+ children: ReactElement<typeof Overlay>[] | ReactElement<typeof Overlay>;
6
+ overlaysShowTimeout?: number;
7
+ persistentlyShowOverlays?: boolean;
8
+ hideOverlaysOnMouseLeave?: boolean;
9
+ showOverlaysOnMouseMove?: boolean;
10
+ skipAllSystemEvents?: boolean;
11
+ unmountContentWhenHidden?: boolean;
12
+ onApiUpdated?: (api: BoundedOverlayManagerApi) => void;
13
+ };
14
+ declare const BoundedOverlayManagerContent: React.FC<Props>;
15
+ export default BoundedOverlayManagerContent;
@@ -0,0 +1,46 @@
1
+ import { jsx as v } from "react/jsx-runtime";
2
+ import { useState as L, useRef as T, useEffect as A, useCallback as a, useLayoutEffect as l } from "react";
3
+ import R from "../hooks/useResizeObserver.js";
4
+ import { copyComponentBoundingBox as U } from "../util/bbox.js";
5
+ import D from "./OverlaysContainer.js";
6
+ import N from "../hooks/useOverlayManagerEvents.js";
7
+ import C from "../hooks/useForwardBoundingComponentEvents.js";
8
+ import g from "../hooks/useTimedEventManager.js";
9
+ import { useOverlayManagerContext as F } from "../context/OverlayManagerContext.js";
10
+ import H from "../hooks/useApiUpdateHandler.js";
11
+ import V from "../hooks/useWindowResize.js";
12
+ import { DEFAULT_OVERLAYS_SHOW_TIMEOUT as B, DEFAULT_PERSISTANTLY_SHOW_OVERLAYS as Y, DEFAULT_SKIP_ALL_SYSTEM_EVENTS as w, DEFAULT_HIDE_OVERLAYS_ON_MOUSE_LEAVE as x, DEFAULT_SHOW_OVERLAYS_ON_MOUSE_MOVE as y, DEFAULT_UNMOUNT_CONTENT_WHEN_HIDDEN as I } from "../config.js";
13
+ const Z = ({
14
+ children: i,
15
+ overlaysShowTimeout: m = B,
16
+ persistentlyShowOverlays: o = Y,
17
+ skipAllSystemEvents: s = w,
18
+ hideOverlaysOnMouseLeave: E = x,
19
+ showOverlaysOnMouseMove: f = y,
20
+ unmountContentWhenHidden: O = I,
21
+ onApiUpdated: _
22
+ }) => {
23
+ const { boundingComponentRef: t } = F(), [d, n] = L(o), r = T(null);
24
+ A(() => {
25
+ n(o);
26
+ }, [o]);
27
+ const p = a(() => n(!0), []), M = a(() => n(!1), []), u = g({ onStart: p, onStop: M, timeoutDuration: m, returnNull: o }), S = f && !s, c = E && !s, e = a(() => {
28
+ window.requestAnimationFrame(() => {
29
+ U(t, r);
30
+ });
31
+ }, [t, r]);
32
+ return C(), H({
33
+ timedEventManager: u,
34
+ onApiUpdated: _,
35
+ updateOverlaysContainerBoundingBox: e
36
+ }), N({
37
+ timedEventManager: u,
38
+ requestStartOnMouseMove: S,
39
+ requestStopOnMouseMove: c
40
+ }), V({ handleResize: e }), R(t, { handleResize: e }), l(() => {
41
+ e();
42
+ }, [e]), /* @__PURE__ */ v(D, { ref: r, show: d, unmountContentWhenHidden: O, children: i });
43
+ };
44
+ export {
45
+ Z as default
46
+ };
@@ -0,0 +1,26 @@
1
+ /// <reference types="react" />
2
+ import PredefinedPosition from "../enum/PredefinedPosition";
3
+ import { BottomCenterOffsetProps, BottomLeftOffsetProps, BottomRightOffsetProps, CenterOffsetProps, MidLeftOffsetProps, MidRightOffsetProps, TopCenterOffsetProps, TopLeftOffsetProps, TopRightOffsetProps } from "../types/OffsetProps";
4
+ export declare const overlayClassName: string;
5
+ type PositionOffsetMapping = {
6
+ [PredefinedPosition.TOP_LEFT]: TopLeftOffsetProps;
7
+ [PredefinedPosition.BOTTOM_CENTER]: BottomCenterOffsetProps;
8
+ [PredefinedPosition.TOP_RIGHT]: TopRightOffsetProps;
9
+ [PredefinedPosition.BOTTOM_LEFT]: BottomLeftOffsetProps;
10
+ [PredefinedPosition.BOTTOM_RIGHT]: BottomRightOffsetProps;
11
+ [PredefinedPosition.TOP_CENTER]: TopCenterOffsetProps;
12
+ [PredefinedPosition.MID_LEFT]: MidLeftOffsetProps;
13
+ [PredefinedPosition.MID_RIGHT]: MidRightOffsetProps;
14
+ [PredefinedPosition.CENTER]: CenterOffsetProps;
15
+ };
16
+ type OverlayPositionProps = {
17
+ [P in keyof PositionOffsetMapping]: {
18
+ position: P;
19
+ offset?: PositionOffsetMapping[P];
20
+ };
21
+ }[keyof PositionOffsetMapping];
22
+ type Props = OverlayPositionProps & {
23
+ children?: React.ReactNode;
24
+ };
25
+ declare const Overlay: React.FC<Props>;
26
+ export default Overlay;
@@ -0,0 +1,43 @@
1
+ import "../../assets/Overlay.css";
2
+ import { jsx as y } from "react/jsx-runtime";
3
+ import { useRef as T, useCallback as u, useState as v, useEffect as O } from "react";
4
+ import t from "../enum/PredefinedPosition.js";
5
+ import P from "../hooks/useForwardOverlayEvents.js";
6
+ import { useOverlayManagerContext as E } from "../context/OverlayManagerContext.js";
7
+ const _ = "_overlay_ractj_1", C = {
8
+ overlay: _
9
+ }, I = C.overlay, R = {
10
+ top: 0,
11
+ bottom: 0,
12
+ left: 0,
13
+ right: 0,
14
+ topInPercent: 0,
15
+ leftInPercent: 0
16
+ }, d = (s, a) => {
17
+ if (!s.current)
18
+ return {};
19
+ const { position: f, offset: l } = a, { top: o, bottom: e, left: r, right: n, topInPercent: m, leftInPercent: p } = {
20
+ ...R,
21
+ ...l
22
+ }, c = `${50 + p}%`, i = `${50 + m}%`;
23
+ return {
24
+ [t.BOTTOM_CENTER]: { bottom: e, left: c, transform: "translateX(-50%)" },
25
+ [t.TOP_LEFT]: { top: o, left: r },
26
+ [t.TOP_RIGHT]: { top: o, right: n },
27
+ [t.CENTER]: { top: i, left: c, transform: "translate(-50%, -50%)" },
28
+ [t.BOTTOM_LEFT]: { bottom: e, left: r },
29
+ [t.BOTTOM_RIGHT]: { bottom: e, right: n },
30
+ [t.TOP_CENTER]: { top: o, left: c, transform: "translateX(-50%)" },
31
+ [t.MID_LEFT]: { top: i, left: r, transform: "translateY(-50%)" },
32
+ [t.MID_RIGHT]: { top: i, right: n, transform: "translateY(-50%)" }
33
+ }[f] || {};
34
+ }, h = ({ offset: s, position: a, children: f }) => {
35
+ const l = T(null), { boundingComponentRef: o } = E(), e = u(() => d(o, { position: a, offset: s }), [o, a, s]), [r, n] = v(e);
36
+ return P({ overlayRef: l }), O(() => {
37
+ n(e());
38
+ }, [e]), /* @__PURE__ */ y("div", { ref: l, className: I, role: "overlay", style: r, children: f });
39
+ };
40
+ export {
41
+ h as default,
42
+ I as overlayClassName
43
+ };
@@ -0,0 +1,11 @@
1
+ import React, { ReactElement } from 'react';
2
+ import Overlay from './Overlay';
3
+ export declare const overlaysContainerClassName: string;
4
+ export declare const overlaysContainerContentClassName: string;
5
+ type Props = {
6
+ children: ReactElement<typeof Overlay>[] | ReactElement<typeof Overlay>;
7
+ show: boolean;
8
+ unmountContentWhenHidden: boolean;
9
+ };
10
+ declare const _default: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>;
11
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import "../../assets/OverlaysContainer.css";
2
+ import { jsx as o } from "react/jsx-runtime";
3
+ import s from "react";
4
+ const l = "_overlaysContainer_wi19r_1", i = "_overlaysContainerContent_wi19r_6", t = {
5
+ overlaysContainer: l,
6
+ overlaysContainerContent: i
7
+ }, C = t.overlaysContainer, c = t.overlaysContainerContent, y = ({ children: e, show: n, unmountContentWhenHidden: a }, r) => /* @__PURE__ */ o("div", { role: "overlays-container", className: C, ref: r, children: a && !n ? null : /* @__PURE__ */ o("div", { role: "overlays-container-content", className: c, style: { display: n ? "block" : "none" }, children: e }) }), f = s.forwardRef(y);
8
+ export {
9
+ f as default,
10
+ C as overlaysContainerClassName,
11
+ c as overlaysContainerContentClassName
12
+ };
@@ -0,0 +1,37 @@
1
+ import { jsx as r } from "react/jsx-runtime";
2
+ import { s as i, a as m } from "../../../react.esm-GKFzux-6.js";
3
+ import u from "../BoundedOverlayManager.js";
4
+ import "../../../index-7ofMxoL9.js";
5
+ jest.mock("../../context/OverlayManagerContext", () => ({
6
+ OverlayManagerContextProvider: ({ children: t, boundingComponentRef: e }) => (e == null || e(), t)
7
+ }));
8
+ jest.mock("../BoundedOverlayManagerContent", () => ({
9
+ __esModule: !0,
10
+ default: ({ children: t }) => /* @__PURE__ */ r("div", { children: t })
11
+ }));
12
+ describe("BoundedOverlayManager", () => {
13
+ let t, e;
14
+ const o = "mock-test-id", d = () => /* @__PURE__ */ r("div", { "data-testid": o }), c = () => i.queryByTestId(o), s = () => {
15
+ t = document.fullscreenElement, e = document.createElement("div"), document.body.appendChild(e), Object.defineProperty(document, "fullscreenElement", {
16
+ value: e,
17
+ writable: !0
18
+ });
19
+ }, a = () => {
20
+ Object.defineProperty(document, "fullscreenElement", {
21
+ value: t,
22
+ writable: !0
23
+ }), document.body.removeChild(e);
24
+ }, l = (n) => {
25
+ n = n || jest.fn(), m(
26
+ /* @__PURE__ */ r(u, { boundingComponentRef: n, children: /* @__PURE__ */ r(d, {}) })
27
+ );
28
+ };
29
+ it("renders content into the fullscreen element when in fullscreen mode", () => {
30
+ s(), l(), expect(e).toContainElement(c()), a();
31
+ }), it("renders the content into document.body when not in fullscreen mode", () => {
32
+ l(), expect(document.body).toContainElement(c());
33
+ }), it("boudingComponentRef is passed to the provider", () => {
34
+ const n = jest.fn();
35
+ l(n), expect(n).toHaveBeenCalled();
36
+ });
37
+ });
@@ -0,0 +1,92 @@
1
+ import { jsx as e } from "react/jsx-runtime";
2
+ import c from "react";
3
+ import { a as s } from "../../../react.esm-GKFzux-6.js";
4
+ import "../../../index-7ofMxoL9.js";
5
+ import n from "../BoundedOverlayManagerContent.js";
6
+ import { useOverlayManagerContext as v } from "../../context/OverlayManagerContext.js";
7
+ import d from "../../hooks/useTimedEventManager.js";
8
+ import u from "../../hooks/useForwardBoundingComponentEvents.js";
9
+ import h from "../../hooks/useOverlayManagerEvents.js";
10
+ import m from "../../hooks/useResizeObserver.js";
11
+ import { makeEventOnlyMockComponentRef as p } from "../../hooks/test/util.js";
12
+ import O from "../../hooks/useApiUpdateHandler.js";
13
+ jest.mock("../../hooks/useTimedEventManager");
14
+ jest.mock("../../hooks/useForwardBoundingComponentEvents");
15
+ jest.mock("../../hooks/useOverlayManagerEvents");
16
+ jest.mock("../../hooks/useResizeObserver");
17
+ jest.mock("../../hooks/useApiUpdateHandler");
18
+ jest.mock("../../util/bbox", () => ({ copyComponentBoundingBox: jest.fn() }));
19
+ jest.mock("../OverlaysContainer", () => c.forwardRef(({ children: a, show: t }, r) => /* @__PURE__ */ e("div", { ref: r, "data-testid": "overlays-container", "data-show": t, children: a })));
20
+ jest.mock("../../context/OverlayManagerContext");
21
+ describe("BoundedOverlayManagerContent", () => {
22
+ let a;
23
+ beforeEach(() => {
24
+ a = p(), v.mockReturnValue({
25
+ boundingComponentRef: a
26
+ });
27
+ }), afterEach(() => {
28
+ jest.clearAllMocks();
29
+ }), it("calls useTimedEventManager with the correct arguments", () => {
30
+ s(
31
+ /* @__PURE__ */ e(n, { children: /* @__PURE__ */ e("div", { children: "Mock Children" }) })
32
+ ), expect(d).toHaveBeenCalledWith(expect.objectContaining({
33
+ onStart: expect.any(Function),
34
+ onStop: expect.any(Function),
35
+ timeoutDuration: 2e3,
36
+ returnNull: !1
37
+ }));
38
+ }), it("calls useForwardBoundingComponentEvents", () => {
39
+ s(
40
+ /* @__PURE__ */ e(n, { children: /* @__PURE__ */ e("div", { children: "Mock Children" }) })
41
+ ), expect(u).toHaveBeenCalled();
42
+ }), it.each([
43
+ {
44
+ showOverlaysOnMouseMove: !0,
45
+ hideOverlaysOnMouseLeave: !1,
46
+ skipAllSystemEvents: !1
47
+ },
48
+ {
49
+ showOverlaysOnMouseMove: !1,
50
+ hideOverlaysOnMouseLeave: !0,
51
+ skipAllSystemEvents: !1
52
+ },
53
+ {
54
+ showOverlaysOnMouseMove: !0,
55
+ hideOverlaysOnMouseLeave: !0,
56
+ skipAllSystemEvents: !0
57
+ },
58
+ {
59
+ showOverlaysOnMouseMove: !1,
60
+ hideOverlaysOnMouseLeave: !1,
61
+ skipAllSystemEvents: !0
62
+ }
63
+ ])("calls useOverlayManagerEvents with the correct arguments when showOverlaysOnMouseMove is $showOverlaysOnMouseMove, hideOverlaysOnMouseLeave is $hideOverlaysOnMouseLeave and skipAllSystemEvents is $skipAllSystemEvents", ({ showOverlaysOnMouseMove: t, hideOverlaysOnMouseLeave: r, skipAllSystemEvents: o }) => {
64
+ const i = t && !o, l = r && !o;
65
+ s(
66
+ /* @__PURE__ */ e(n, { showOverlaysOnMouseMove: t, hideOverlaysOnMouseLeave: r, skipAllSystemEvents: o, children: /* @__PURE__ */ e("div", { children: "Mock Children" }) })
67
+ ), expect(h).toHaveBeenCalledWith(expect.objectContaining({
68
+ requestStartOnMouseMove: i,
69
+ requestStopOnMouseMove: l
70
+ }));
71
+ }), it("calls useResizeObserver with the correct arguments", () => {
72
+ s(
73
+ /* @__PURE__ */ e(n, { children: /* @__PURE__ */ e("div", { children: "Mock Children" }) })
74
+ ), expect(m).toHaveBeenCalledWith(a, expect.objectContaining({
75
+ handleResize: expect.any(Function)
76
+ }));
77
+ }), it("renders OverlaysContainer with the correct props and children", () => {
78
+ const { getByTestId: t, rerender: r } = s(
79
+ /* @__PURE__ */ e(n, { persistentlyShowOverlays: !0, children: /* @__PURE__ */ e("div", { children: "Test Overlay" }) })
80
+ ), o = t("overlays-container");
81
+ expect(o).toHaveAttribute("data-show", "true"), expect(o).toHaveTextContent("Test Overlay"), r(
82
+ /* @__PURE__ */ e(n, { persistentlyShowOverlays: !1, children: /* @__PURE__ */ e("div", { children: "Test Overlay" }) })
83
+ ), expect(o).toHaveAttribute("data-show", "false");
84
+ }), it("calls useApiUpdateHandler with the correct arguments", () => {
85
+ const t = jest.fn();
86
+ s(
87
+ /* @__PURE__ */ e(n, { onApiUpdated: t, children: /* @__PURE__ */ e("div", { children: "Test Overlay" }) })
88
+ ), expect(O).toHaveBeenCalledWith(expect.objectContaining({
89
+ onApiUpdated: t
90
+ }));
91
+ });
92
+ });
File without changes
@@ -0,0 +1,245 @@
1
+ import { jsx as o } from "react/jsx-runtime";
2
+ import { a as r } from "../../../react.esm-GKFzux-6.js";
3
+ import "../../../index-7ofMxoL9.js";
4
+ import n, { overlayClassName as c } from "../Overlay.js";
5
+ import t from "../../enum/PredefinedPosition.js";
6
+ import { useOverlayManagerContext as f } from "../../context/OverlayManagerContext.js";
7
+ import d from "../../hooks/useForwardOverlayEvents.js";
8
+ const T = [
9
+ {
10
+ positionProps: {
11
+ position: t.TOP_LEFT
12
+ },
13
+ expectedStyle: {
14
+ top: 0,
15
+ left: 0
16
+ }
17
+ },
18
+ {
19
+ positionProps: {
20
+ position: t.TOP_LEFT,
21
+ offset: { top: "10%", left: "10%" }
22
+ },
23
+ expectedStyle: {
24
+ top: "10%",
25
+ left: "10%"
26
+ }
27
+ },
28
+ {
29
+ positionProps: {
30
+ position: t.BOTTOM_CENTER
31
+ },
32
+ expectedStyle: {
33
+ bottom: 0,
34
+ left: "50%",
35
+ transform: "translateX(-50%)"
36
+ }
37
+ },
38
+ {
39
+ positionProps: {
40
+ position: t.TOP_RIGHT
41
+ },
42
+ expectedStyle: {
43
+ top: 0,
44
+ right: 0
45
+ }
46
+ },
47
+ {
48
+ positionProps: {
49
+ position: t.TOP_RIGHT,
50
+ offset: { top: "10%", right: "10%" }
51
+ },
52
+ expectedStyle: {
53
+ top: "10%",
54
+ right: "10%"
55
+ }
56
+ },
57
+ {
58
+ positionProps: {
59
+ position: t.BOTTOM_LEFT
60
+ },
61
+ expectedStyle: {
62
+ bottom: 0,
63
+ left: 0
64
+ }
65
+ },
66
+ {
67
+ positionProps: {
68
+ position: t.BOTTOM_LEFT,
69
+ offset: { bottom: "10%", left: "10%" }
70
+ },
71
+ expectedStyle: {
72
+ bottom: "10%",
73
+ left: "10%"
74
+ }
75
+ },
76
+ {
77
+ positionProps: {
78
+ position: t.BOTTOM_RIGHT
79
+ },
80
+ expectedStyle: {
81
+ bottom: 0,
82
+ right: 0
83
+ }
84
+ },
85
+ {
86
+ positionProps: {
87
+ position: t.BOTTOM_RIGHT,
88
+ offset: { bottom: "10%", right: "10%" }
89
+ },
90
+ expectedStyle: {
91
+ bottom: "10%",
92
+ right: "10%"
93
+ }
94
+ },
95
+ {
96
+ positionProps: {
97
+ position: t.TOP_CENTER
98
+ },
99
+ expectedStyle: {
100
+ top: 0,
101
+ left: "50%",
102
+ transform: "translateX(-50%)"
103
+ }
104
+ },
105
+ {
106
+ positionProps: {
107
+ position: t.TOP_CENTER,
108
+ offset: { leftInPercent: 10 }
109
+ },
110
+ expectedStyle: {
111
+ top: 0,
112
+ left: "60%",
113
+ transform: "translateX(-50%)"
114
+ }
115
+ },
116
+ {
117
+ positionProps: {
118
+ position: t.BOTTOM_CENTER,
119
+ offset: { leftInPercent: 10 }
120
+ },
121
+ expectedStyle: {
122
+ bottom: 0,
123
+ left: "60%",
124
+ transform: "translateX(-50%)"
125
+ }
126
+ },
127
+ {
128
+ positionProps: {
129
+ position: t.CENTER
130
+ },
131
+ expectedStyle: {
132
+ top: "50%",
133
+ left: "50%",
134
+ transform: "translate(-50%, -50%)"
135
+ }
136
+ },
137
+ {
138
+ positionProps: {
139
+ position: t.CENTER,
140
+ offset: { topInPercent: 10, leftInPercent: 10 }
141
+ },
142
+ expectedStyle: {
143
+ top: "60%",
144
+ left: "60%",
145
+ transform: "translate(-50%, -50%)"
146
+ }
147
+ },
148
+ {
149
+ positionProps: {
150
+ position: t.MID_LEFT
151
+ },
152
+ expectedStyle: {
153
+ top: "50%",
154
+ left: 0,
155
+ transform: "translateY(-50%)"
156
+ }
157
+ },
158
+ {
159
+ positionProps: {
160
+ position: t.MID_LEFT,
161
+ offset: { topInPercent: 10, left: "10%" }
162
+ },
163
+ expectedStyle: {
164
+ top: "60%",
165
+ left: "10%",
166
+ transform: "translateY(-50%)"
167
+ }
168
+ },
169
+ {
170
+ positionProps: {
171
+ position: t.MID_RIGHT
172
+ },
173
+ expectedStyle: {
174
+ top: "50%",
175
+ right: 0,
176
+ transform: "translateY(-50%)"
177
+ }
178
+ },
179
+ {
180
+ positionProps: {
181
+ position: t.MID_RIGHT,
182
+ offset: { topInPercent: 10, right: "10%" }
183
+ },
184
+ expectedStyle: {
185
+ top: "60%",
186
+ right: "10%",
187
+ transform: "translateY(-50%)"
188
+ }
189
+ }
190
+ ];
191
+ jest.mock("../../context/OverlayManagerContext");
192
+ jest.mock("../../hooks/useForwardBoundingComponentEvents");
193
+ jest.mock("../../hooks/useResizeObserver");
194
+ jest.mock("../../hooks/useForwardOverlayEvents", () => ({
195
+ __esModule: !0,
196
+ // This property is needed for mocking default exports
197
+ default: jest.fn()
198
+ }));
199
+ describe("Overlay Component", () => {
200
+ const a = { current: document.createElement("div") };
201
+ beforeEach(() => {
202
+ f.mockReturnValue({
203
+ boundingComponentRef: a
204
+ });
205
+ }), it.each(T)("applies correct styles for position $positionProps.position and offset $positionProps.offset", ({ positionProps: e, expectedStyle: i }) => {
206
+ const { getByRole: s } = r(
207
+ /* @__PURE__ */ o(n, { ...e, children: "Test Content" })
208
+ ), p = s("overlay");
209
+ expect(p).toHaveStyle(i);
210
+ }), it("useForwardOverlayEvents is called with correct arguments", () => {
211
+ r(
212
+ /* @__PURE__ */ o(n, { position: t.TOP_LEFT, children: "Test Content" })
213
+ ), expect(d).toHaveBeenCalledWith(expect.objectContaining({
214
+ overlayRef: expect.anything()
215
+ }));
216
+ }), it("renders children", () => {
217
+ const e = "child-testid", i = /* @__PURE__ */ o("div", { "data-testid": e, children: "Test Child" }), { getByTestId: s } = r(
218
+ /* @__PURE__ */ o(n, { position: t.TOP_LEFT, children: i })
219
+ );
220
+ expect(s(e)).toBeInTheDocument();
221
+ }), it("overlay element has the correct class name", () => {
222
+ const { getByRole: e } = r(
223
+ /* @__PURE__ */ o(n, { position: t.TOP_LEFT, children: "Test Content" })
224
+ );
225
+ expect(e("overlay")).toHaveClass(c);
226
+ }), it("updates as expected when position prop is updated", () => {
227
+ const { rerender: e, getByRole: i } = r(
228
+ /* @__PURE__ */ o(n, { position: t.TOP_CENTER, children: "Test Content" })
229
+ );
230
+ let s = i("overlay");
231
+ expect(s).toHaveStyle({ top: 0, left: "50%" }), e(
232
+ /* @__PURE__ */ o(n, { position: t.CENTER, children: "Test Content" })
233
+ ), expect(s).toHaveStyle({ top: "50%", left: "50%" });
234
+ }), it("updates as expected when offset prop is updated", () => {
235
+ const e = { top: "10%", left: "10%" }, { rerender: i, getByRole: s } = r(
236
+ /* @__PURE__ */ o(n, { position: t.TOP_LEFT, offset: e, children: "Test Content" })
237
+ );
238
+ let p = s("overlay");
239
+ expect(p).toHaveStyle(e);
240
+ const l = { top: "20%", left: "20%" };
241
+ i(
242
+ /* @__PURE__ */ o(n, { position: t.TOP_LEFT, offset: l, children: "Test Content" })
243
+ ), expect(p).toHaveStyle(l);
244
+ });
245
+ });
@@ -0,0 +1,36 @@
1
+ import { jsx as t } from "react/jsx-runtime";
2
+ import r, { overlaysContainerClassName as d, overlaysContainerContentClassName as h } from "../OverlaysContainer.js";
3
+ import "../../../index-7ofMxoL9.js";
4
+ import { a as i } from "../../../react.esm-GKFzux-6.js";
5
+ const u = (s) => s.querySelector("[role='overlays-container']"), l = (s) => s.querySelector("[role='overlays-container-content']");
6
+ describe("OverlaysContainer", () => {
7
+ const s = "Mock Child", c = "mock-child-id", o = /* @__PURE__ */ t("div", { "data-testid": c, children: s });
8
+ it("renders children", () => {
9
+ const { getByTestId: e } = i(
10
+ /* @__PURE__ */ t(r, { show: !0, unmountContentWhenHidden: !1, children: o })
11
+ );
12
+ expect(e(c)).toBeInTheDocument();
13
+ }), it("toggles visibility of content based on show prop", () => {
14
+ const { rerender: e, container: a } = i(
15
+ /* @__PURE__ */ t(r, { show: !1, unmountContentWhenHidden: !1, children: o })
16
+ );
17
+ let n = l(a);
18
+ expect(n).toHaveStyle("display: none"), e(
19
+ /* @__PURE__ */ t(r, { show: !0, unmountContentWhenHidden: !1, children: o })
20
+ ), expect(n).toHaveStyle("display: block");
21
+ }), it("unmounts content when hidden and unmountContentWhenHidden prop is true", () => {
22
+ const { rerender: e, container: a } = i(
23
+ /* @__PURE__ */ t(r, { show: !0, unmountContentWhenHidden: !0, children: o })
24
+ );
25
+ let n = l(a);
26
+ expect(n).toBeInTheDocument(), e(
27
+ /* @__PURE__ */ t(r, { show: !1, unmountContentWhenHidden: !0, children: o })
28
+ ), expect(n).not.toBeInTheDocument();
29
+ }), it("overlays container and the content divs has correct class name", () => {
30
+ const { container: e } = i(
31
+ /* @__PURE__ */ t(r, { show: !0, unmountContentWhenHidden: !1, children: o })
32
+ );
33
+ let a = u(e), n = l(e);
34
+ expect(a).toHaveClass(d), expect(n).toHaveClass(h);
35
+ });
36
+ });
@@ -0,0 +1,6 @@
1
+ export declare const DEFAULT_OVERLAYS_SHOW_TIMEOUT = 2000;
2
+ export declare const DEFAULT_PERSISTANTLY_SHOW_OVERLAYS = false;
3
+ export declare const DEFAULT_SKIP_ALL_SYSTEM_EVENTS = false;
4
+ export declare const DEFAULT_HIDE_OVERLAYS_ON_MOUSE_LEAVE = true;
5
+ export declare const DEFAULT_SHOW_OVERLAYS_ON_MOUSE_MOVE = true;
6
+ export declare const DEFAULT_UNMOUNT_CONTENT_WHEN_HIDDEN = false;
@@ -0,0 +1,9 @@
1
+ const E = 2e3, _ = !1, O = !1, S = !0, T = !0, L = !1;
2
+ export {
3
+ S as DEFAULT_HIDE_OVERLAYS_ON_MOUSE_LEAVE,
4
+ E as DEFAULT_OVERLAYS_SHOW_TIMEOUT,
5
+ _ as DEFAULT_PERSISTANTLY_SHOW_OVERLAYS,
6
+ T as DEFAULT_SHOW_OVERLAYS_ON_MOUSE_MOVE,
7
+ O as DEFAULT_SKIP_ALL_SYSTEM_EVENTS,
8
+ L as DEFAULT_UNMOUNT_CONTENT_WHEN_HIDDEN
9
+ };