asma-ui-core 3.61.4 → 3.63.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.
@@ -1,25 +1,27 @@
1
1
  import { cn as f } from "../../../helpers/cn.js";
2
- import { resolveSx as S } from "../../../helpers/sx.js";
2
+ import { resolveSx as D } from "../../../helpers/sx.js";
3
3
  import { CloseIcon as X } from "../../icons/close-icon/CloseIcon.js";
4
- import { StyledButton as B } from "../../inputs/button/StyledButton.js";
5
- import { useMobileMediaQuery as G } from "../../../hooks/useMediaQuery.hook.js";
6
- import P from "./StyledDialog.module.js";
7
- import { useEffect as D, useLayoutEffect as Q, useRef as u } from "react";
8
- import { jsx as l, jsxs as r } from "react/jsx-runtime";
9
- var $ = {
4
+ import { registerOpenModalDialog as B } from "../../../hooks/useTopLayer.hook.js";
5
+ import { StyledButton as G } from "../../inputs/button/StyledButton.js";
6
+ import { useMobileMediaQuery as P } from "../../../hooks/useMediaQuery.hook.js";
7
+ import Q from "./StyledDialog.module.js";
8
+ import { useEffect as S, useLayoutEffect as $, useRef as u } from "react";
9
+ import { jsx as r, jsxs as l } from "react/jsx-runtime";
10
+ var J = {
10
11
  xs: 444,
11
12
  sm: 600,
12
13
  md: 900,
13
14
  lg: 1200,
14
15
  xl: 1536
15
- }, te = ({ open: t, onClose: a, children: _, dataTest: i, maxWidth: x = "sm", fullWidth: C, fullScreen: E, scroll: p = "paper", disableEscapeKeyDown: h, className: H, style: j, sx: M, classes: y, PaperProps: R, slotProps: o, onCloseText: w, showCloseIcon: v = !0, dialogLabel: d, dialogTitle: s, dialogHeaderNode: W }) => {
16
- const I = G(), b = u(null), c = u(!1), g = u(t), n = I ? !0 : E;
17
- D(() => {
16
+ }, le = ({ open: t, onClose: a, children: _, dataTest: i, maxWidth: x = "sm", fullWidth: C, fullScreen: E, scroll: p = "paper", disableEscapeKeyDown: h, className: H, style: j, sx: M, classes: y, PaperProps: O, slotProps: o, onCloseText: w, showCloseIcon: v = !0, dialogLabel: d, dialogTitle: s, dialogHeaderNode: R }) => {
17
+ const W = P(), b = u(null), c = u(!1), g = u(t), n = E ?? W;
18
+ S(() => {
18
19
  g.current && !t && o?.transition?.onExited?.(), g.current = t;
19
- }, [t, o]), Q(() => {
20
+ }, [t, o]), $(() => {
20
21
  const e = b.current;
21
- !e || !t || e.open || (e.showModal(), e.focus({ preventScroll: !0 }), requestAnimationFrame(() => e.open && e.focus({ preventScroll: !0 })));
22
- }, [t]), D(() => {
22
+ if (!(!e || !t))
23
+ return e.open || (e.showModal(), e.focus({ preventScroll: !0 }), requestAnimationFrame(() => e.open && e.focus({ preventScroll: !0 }))), B(e);
24
+ }, [t]), S(() => {
23
25
  if (!t) return;
24
26
  const e = document.body.style.overflow, K = document.documentElement.style.overflow;
25
27
  return document.body.style.overflow = "hidden", document.documentElement.style.overflow = "hidden", () => {
@@ -27,16 +29,16 @@ var $ = {
27
29
  };
28
30
  }, [t]);
29
31
  const m = {
30
- ...R,
32
+ ...O,
31
33
  ...o?.paper
32
- }, k = x === !1 ? void 0 : $[x], { className: O, style: z, onClick: q, ...A } = o?.backdrop ?? {}, N = (e) => {
34
+ }, k = x === !1 ? void 0 : J[x], { className: I, style: z, onClick: q, ...A } = o?.backdrop ?? {}, N = (e) => {
33
35
  c.current || (c.current = !0, window.setTimeout(() => {
34
36
  c.current = !1;
35
37
  }, 0), a?.(e, "escapeKeyDown"));
36
38
  }, F = (e) => {
37
39
  e.preventDefault(), h || N(e);
38
40
  };
39
- return t ? /* @__PURE__ */ r("dialog", {
41
+ return t ? /* @__PURE__ */ l("dialog", {
40
42
  ref: b,
41
43
  tabIndex: -1,
42
44
  "data-testid": i,
@@ -45,20 +47,20 @@ var $ = {
45
47
  onKeyDown: (e) => {
46
48
  e.key !== "Escape" || h || (e.preventDefault(), N(e));
47
49
  },
48
- className: f(P.StyledDialog, "fixed inset-0 m-0 h-full max-h-none w-full max-w-none items-center justify-center overflow-hidden border-0 bg-transparent p-0 outline-none open:flex", p === "body" && "overflow-y-auto", H, y?.root),
50
+ className: f(Q.StyledDialog, "fixed inset-0 m-0 h-full max-h-none w-full max-w-none items-center justify-center overflow-hidden border-0 bg-transparent p-0 outline-none open:flex", p === "body" && "overflow-y-auto", H, y?.root),
49
51
  style: {
50
52
  zIndex: 999,
51
- ...S(M),
53
+ ...D(M),
52
54
  ...j
53
55
  },
54
- children: [/* @__PURE__ */ l("div", {
56
+ children: [/* @__PURE__ */ r("div", {
55
57
  ...A,
56
- className: f("absolute inset-0 bg-[#626e7eb2]", O),
58
+ className: f("absolute inset-0 bg-[#626e7eb2]", I),
57
59
  style: z,
58
60
  onClick: (e) => {
59
61
  q?.(e), e.defaultPrevented || a?.(e, "backdropClick");
60
62
  }
61
- }), /* @__PURE__ */ r("div", {
63
+ }), /* @__PURE__ */ l("div", {
62
64
  className: f("relative z-[1] flex overflow-hidden rounded-lg border-0 bg-white p-0 text-delta-800 shadow-[0px_4px_40px_0px_#22213366]", p === "paper" && "flex-col", n && "rounded-none", m.className, y?.paper),
63
65
  style: {
64
66
  minWidth: 0,
@@ -73,7 +75,7 @@ var $ = {
73
75
  width: C ? "calc(100% - 64px)" : "auto",
74
76
  maxHeight: "100%"
75
77
  },
76
- ...S(m.sx),
78
+ ...D(m.sx),
77
79
  ...m.style,
78
80
  ...n ? {
79
81
  width: "100%",
@@ -82,25 +84,25 @@ var $ = {
82
84
  maxHeight: "100%"
83
85
  } : { maxHeight: "calc(100% - 64px)" }
84
86
  },
85
- children: [(!!d || !!s || v) && /* @__PURE__ */ r("div", {
87
+ children: [(!!d || !!s || v) && /* @__PURE__ */ l("div", {
86
88
  className: "box-border flex w-full min-w-0 max-w-full justify-between px-4 pt-4",
87
- children: [/* @__PURE__ */ r("div", {
89
+ children: [/* @__PURE__ */ l("div", {
88
90
  className: "flex min-w-0 flex-1 flex-col justify-start gap-0.5",
89
- children: [d && /* @__PURE__ */ l("div", {
91
+ children: [d && /* @__PURE__ */ r("div", {
90
92
  className: "flex h-8 items-center text-sm font-normal leading-5 text-delta-600",
91
93
  children: d
92
- }), s && /* @__PURE__ */ l("div", {
94
+ }), s && /* @__PURE__ */ r("div", {
93
95
  className: "flex text-2xl font-semibold leading-8 text-delta-800",
94
96
  children: s
95
97
  })]
96
- }), v && /* @__PURE__ */ r("div", {
98
+ }), v && /* @__PURE__ */ l("div", {
97
99
  className: "flex min-w-0 max-w-full shrink-0 justify-end gap-2",
98
- children: [W, /* @__PURE__ */ l(B, {
100
+ children: [R, /* @__PURE__ */ r(G, {
99
101
  dataTest: `close-button-${i}`,
100
102
  "aria-label": w ? void 0 : "Close",
101
103
  variant: "textGray",
102
104
  size: "small",
103
- endIcon: /* @__PURE__ */ l(X, {
105
+ endIcon: /* @__PURE__ */ r(X, {
104
106
  width: 20,
105
107
  height: 20
106
108
  }),
@@ -119,5 +121,5 @@ var $ = {
119
121
  }) : null;
120
122
  };
121
123
  export {
122
- te as StyledDialog
124
+ le as StyledDialog
123
125
  };
@@ -1,26 +1,40 @@
1
- import { StyledAlertSnackbar as o } from "./StyledAlertSnackbar.js";
2
- import { StyledDefaultSnackbar as t } from "./components/StyledDefaultSnackbar.js";
3
- import { StyledInfoSnackbar as a } from "./components/StyledInfoSnackbar.js";
4
- import { jsx as i } from "react/jsx-runtime";
5
- import { SnackbarProvider as e } from "notistack";
6
- var d = (r) => /* @__PURE__ */ i(e, {
7
- ...r,
8
- Components: {
9
- alert: o,
10
- info: a,
11
- default: t
12
- },
13
- autoHideDuration: 6e3,
14
- anchorOrigin: {
15
- vertical: "top",
16
- horizontal: "right"
17
- },
18
- domRoot: document.body,
19
- maxSnack: 3,
20
- classes: { root: "min-w-fit flex justify-center" },
21
- className: "w-fit min-w-fit max-w-fit",
22
- children: r.children
23
- });
1
+ import { useTopmostOpenModalDialog as a } from "../../../hooks/useTopLayer.hook.js";
2
+ import { StyledAlertSnackbar as n } from "./StyledAlertSnackbar.js";
3
+ import { StyledDefaultSnackbar as i } from "./components/StyledDefaultSnackbar.js";
4
+ import { StyledInfoSnackbar as m } from "./components/StyledInfoSnackbar.js";
5
+ import { useLayoutEffect as e, useState as s } from "react";
6
+ import { jsx as c } from "react/jsx-runtime";
7
+ import { SnackbarProvider as l } from "notistack";
8
+ var d = () => {
9
+ const [t] = s(() => {
10
+ const o = document.createElement("div");
11
+ return o.style.display = "contents", o.setAttribute("data-asma-snackbar-host", ""), o;
12
+ }), r = a();
13
+ return e(() => {
14
+ const o = r ?? document.body;
15
+ t.parentElement !== o && o.appendChild(t);
16
+ }, [t, r]), e(() => () => t.remove(), [t]), t;
17
+ }, v = (t) => {
18
+ const r = d();
19
+ return /* @__PURE__ */ c(l, {
20
+ ...t,
21
+ Components: {
22
+ alert: n,
23
+ info: m,
24
+ default: i
25
+ },
26
+ autoHideDuration: 6e3,
27
+ anchorOrigin: {
28
+ vertical: "top",
29
+ horizontal: "right"
30
+ },
31
+ domRoot: r,
32
+ maxSnack: 3,
33
+ classes: { root: "min-w-fit flex justify-center" },
34
+ className: "w-fit min-w-fit max-w-fit",
35
+ children: t.children
36
+ });
37
+ };
24
38
  export {
25
- d as SnackbarProvider
39
+ v as SnackbarProvider
26
40
  };
@@ -1,36 +1,41 @@
1
1
  import { cn as c } from "../../../helpers/cn.js";
2
- import { useEffect as p } from "react";
3
- import { jsx as l, jsxs as x } from "react/jsx-runtime";
4
- import { FloatingPortal as h } from "@floating-ui/react";
5
- var b = {
2
+ import { useTopmostOpenModalDialog as x } from "../../../hooks/useTopLayer.hook.js";
3
+ import { useEffect as d } from "react";
4
+ import { jsx as l, jsxs as h } from "react/jsx-runtime";
5
+ import { FloatingPortal as b } from "@floating-ui/react";
6
+ var g = {
6
7
  "top-left": "top-6 left-6",
7
8
  "top-center": "top-6 left-1/2 -translate-x-1/2",
8
9
  "top-right": "top-6 right-6",
9
10
  "bottom-left": "bottom-6 left-6",
10
11
  "bottom-center": "bottom-6 left-1/2 -translate-x-1/2",
11
12
  "bottom-right": "bottom-6 right-6"
12
- }, S = ({ open: t = !1, autoHideDuration: e = 3e3, onClose: r, anchorOrigin: o = {
13
+ }, N = ({ open: t = !1, autoHideDuration: e = 3e3, onClose: o, anchorOrigin: r = {
13
14
  vertical: "bottom",
14
15
  horizontal: "left"
15
- }, message: i, action: m, children: a, className: f }) => {
16
- if (p(() => {
16
+ }, message: m, action: i, children: a, className: s }) => {
17
+ const f = x();
18
+ if (d(() => {
17
19
  if (!t || e == null) return;
18
- const s = setTimeout(() => r?.(null, "timeout"), e);
19
- return () => clearTimeout(s);
20
+ const p = setTimeout(() => o?.(null, "timeout"), e);
21
+ return () => clearTimeout(p);
20
22
  }, [
21
23
  t,
22
24
  e,
23
- r
25
+ o
24
26
  ]), !t) return null;
25
- const n = b[`${o.vertical}-${o.horizontal}`];
26
- return /* @__PURE__ */ l(h, { children: /* @__PURE__ */ l("div", {
27
- className: c("fixed z-[1400] flex items-center gap-2", n, f),
28
- children: a ?? /* @__PURE__ */ x("div", {
29
- className: "flex items-center gap-2 rounded bg-delta-800 px-4 py-3 text-sm text-white shadow-lg",
30
- children: [i, m]
27
+ const n = g[`${r.vertical}-${r.horizontal}`];
28
+ return /* @__PURE__ */ l(b, {
29
+ root: f,
30
+ children: /* @__PURE__ */ l("div", {
31
+ className: c("fixed z-[1400] flex items-center gap-2", n, s),
32
+ children: a ?? /* @__PURE__ */ h("div", {
33
+ className: "flex items-center gap-2 rounded bg-delta-800 px-4 py-3 text-sm text-white shadow-lg",
34
+ children: [m, i]
35
+ })
31
36
  })
32
- }) });
37
+ });
33
38
  };
34
39
  export {
35
- S as StyledSnackbar
40
+ N as StyledSnackbar
36
41
  };
@@ -1,29 +1,65 @@
1
- import { useCallback as t } from "react";
2
- var a = { popover: "manual" }, i = {
1
+ import { useCallback as r, useSyncExternalStore as s } from "react";
2
+ var c = { popover: "manual" }, p = {
3
3
  margin: 0,
4
4
  inset: "auto"
5
5
  };
6
- function u(o) {
7
- if (!(o instanceof Element)) return;
8
- const r = o.closest("dialog");
9
- return r instanceof HTMLDialogElement && r.open ? r : void 0;
6
+ function f(e) {
7
+ if (!(e instanceof Element)) return;
8
+ const o = e.closest("dialog");
9
+ return o instanceof HTMLDialogElement && o.open ? o : void 0;
10
10
  }
11
- function p(o) {
12
- return o == null;
11
+ function t() {
12
+ if (typeof window > "u") return a ??= {
13
+ dialogs: [],
14
+ listeners: /* @__PURE__ */ new Set()
15
+ };
16
+ const e = window.rawWindow ?? document.defaultView ?? window;
17
+ return e.__asmaOpenModalDialogRegistry__ ??= {
18
+ dialogs: [],
19
+ listeners: /* @__PURE__ */ new Set()
20
+ };
13
21
  }
14
- function c(o, r = !0) {
15
- return t((e) => {
16
- if (o(e), !(!e || !r))
22
+ var a, i = () => {
23
+ for (const e of [...t().listeners]) e();
24
+ };
25
+ function g(e) {
26
+ return t().dialogs.push(e), i(), () => {
27
+ const { dialogs: o } = t(), n = o.indexOf(e);
28
+ n !== -1 && (o.splice(n, 1), i());
29
+ };
30
+ }
31
+ function l() {
32
+ const { dialogs: e } = t();
33
+ for (let o = e.length - 1; o >= 0; o -= 1) {
34
+ const n = e[o];
35
+ if (n?.isConnected && n.open) return n;
36
+ }
37
+ }
38
+ var u = (e) => (t().listeners.add(e), () => {
39
+ t().listeners.delete(e);
40
+ });
41
+ function w() {
42
+ return s(u, l, () => {
43
+ });
44
+ }
45
+ function v(e) {
46
+ return e == null;
47
+ }
48
+ function O(e, o = !0) {
49
+ return r((n) => {
50
+ if (e(n), !(!n || !o))
17
51
  try {
18
- typeof e.showPopover == "function" && !e.matches(":popover-open") && e.showPopover();
52
+ typeof n.showPopover == "function" && !n.matches(":popover-open") && n.showPopover();
19
53
  } catch {
20
54
  }
21
- }, [o, r]);
55
+ }, [e, o]);
22
56
  }
23
57
  export {
24
- a as TOP_LAYER_PROPS,
25
- i as TOP_LAYER_RESET_STYLE,
26
- u as getOpenModalDialogAncestor,
27
- p as shouldUsePopoverTopLayer,
28
- c as useTopLayerRef
58
+ c as TOP_LAYER_PROPS,
59
+ p as TOP_LAYER_RESET_STYLE,
60
+ f as getOpenModalDialogAncestor,
61
+ g as registerOpenModalDialog,
62
+ v as shouldUsePopoverTopLayer,
63
+ O as useTopLayerRef,
64
+ w as useTopmostOpenModalDialog
29
65
  };
@@ -20,6 +20,7 @@ export interface IStyledDialogProps {
20
20
  dataTest: string;
21
21
  maxWidth?: DialogMaxWidth;
22
22
  fullWidth?: boolean;
23
+ /** Defaults to `true` on mobile (≤743px); pass `false` to keep the windowed paper there too. */
23
24
  fullScreen?: boolean;
24
25
  scroll?: 'paper' | 'body';
25
26
  disableEscapeKeyDown?: boolean;
@@ -44,6 +44,34 @@ export declare const TOP_LAYER_RESET_STYLE: CSSProperties;
44
44
  * body portal.
45
45
  */
46
46
  export declare function getOpenModalDialogAncestor(node: unknown): HTMLElement | undefined;
47
+ declare global {
48
+ interface Window {
49
+ rawWindow?: Window;
50
+ __asmaOpenModalDialogRegistry__?: OpenModalDialogRegistry;
51
+ }
52
+ }
53
+ interface OpenModalDialogRegistry {
54
+ dialogs: HTMLDialogElement[];
55
+ listeners: Set<() => void>;
56
+ }
57
+ /**
58
+ * Publish an open modal `<dialog>` as the current top-layer occupant. Call right after
59
+ * `showModal()`; the returned unregister must run before/as the dialog closes. `StyledDialog` wires
60
+ * this from the same layout effect that opens the dialog.
61
+ */
62
+ export declare function registerOpenModalDialog(dialog: HTMLDialogElement): () => void;
63
+ /**
64
+ * The modal `<dialog>` currently at the top of the browser top layer, or `undefined` when no ui-core
65
+ * modal is open. Stale entries (a dialog torn down without its cleanup running) are skipped rather
66
+ * than trusted, so a missed unregister can never strand an overlay in a detached subtree.
67
+ */
68
+ export declare function getTopmostOpenModalDialog(): HTMLDialogElement | undefined;
69
+ /**
70
+ * Reactive {@link getTopmostOpenModalDialog} — re-renders the caller when a modal `<dialog>` opens or
71
+ * closes. Use as the portal root for an **anchorless** overlay that must clear an open modal
72
+ * (`SnackbarProvider`, `StyledSnackbar`); anchored overlays use {@link getOpenModalDialogAncestor}.
73
+ */
74
+ export declare function useTopmostOpenModalDialog(): HTMLDialogElement | undefined;
47
75
  /**
48
76
  * `true` when the floating node should join the top layer via the Popover API.
49
77
  * `false` when it is (or will be) portalled into an open modal `<dialog>` — see hook docs.
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "3.61.4",
6
+ "version": "3.63.0",
7
7
  "type": "module",
8
8
  "sideEffects": [
9
9
  "**/*.css",